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