Finish Day 1 Part 2

This commit is contained in:
2025-12-02 12:10:27 -06:00
parent 05311bafe0
commit 47083ae033
2 changed files with 51 additions and 8 deletions

View File

@@ -66,24 +66,35 @@ class Day1Command extends Command {
var list = await parseInputFile(fileName);
int dialValue = 50;
int combination = 0;
int combinationPart1 = 0;
int combinationPart2 = 0;
for (var instruction in list) {
switch (instruction.direction) {
case Direction.left:
// Count full rotations
combinationPart2 += (instruction.amount / 100).floor();
// Count additive rotations (remainder + previous value)
if (dialValue != 0 && (dialValue - (instruction.amount % 100)) <= 0) {
combinationPart2++;
}
// Dial counter-clockwise by amount
dialValue -= instruction.amount;
case Direction.right:
// Dial clockwise by amount
dialValue += instruction.amount;
combinationPart2 += (dialValue / 100).floor();
}
dialValue = dialValue % 100;
if (dialValue == 0) {
combination++;
combinationPart1++;
}
}
print("Combination: $combination");
print("Combination - part 1: $combinationPart1");
print("Combination - part 2: $combinationPart2");
}
}