make the two parts structurally similar
This commit is contained in:
@@ -16,11 +16,12 @@ public class Day01 {
|
|||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String instruction = scanner.nextLine();
|
String instruction = scanner.nextLine();
|
||||||
int change = Integer.parseInt(instruction.substring(1));
|
int change = Integer.parseInt(instruction.substring(1));
|
||||||
dial = switch (instruction.charAt(0)) {
|
int step = switch (instruction.charAt(0)) {
|
||||||
case 'L' -> (dial - change) % 100;
|
case 'L' -> -1;
|
||||||
case 'R' -> (dial + change) % 100;
|
case 'R' -> 1;
|
||||||
default -> dial; // impossible
|
default -> 0; // impossible
|
||||||
};
|
};
|
||||||
|
dial = (dial + change * step) % 100;
|
||||||
if (dial == 0) {
|
if (dial == 0) {
|
||||||
password += 1;
|
password += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user