make the two parts structurally similar

This commit is contained in:
2025-12-01 21:20:27 -05:00
parent e7622d74d5
commit 8830face19

View File

@@ -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;
} }