Skip to content

Commit c6a6523

Browse files
committed
2025 day 1: solve part 2
1 parent 7406ded commit c6a6523

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Day 1:
22
3
3+
6

2025/src/day01.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,32 @@ int main(int argc, char **argv) {
1414
std::ifstream infile = aoc::parse_args(argc, argv).infile;
1515

1616
auto rotations = aoc::day01::read_input(infile);
17+
int dial, part1, part2;
1718

18-
int dial = 50;
19-
int part1 = 0;
19+
dial = 50;
20+
part1 = 0;
2021
for (const auto rot : rotations) {
2122
dial += rot;
2223
dial %= 100;
2324
if (dial == 0) {
2425
++part1;
2526
}
2627
}
27-
2828
std::cout << part1 << "\n";
2929

30+
dial = 50;
31+
part2 = 0;
32+
for (const auto rot : rotations) {
33+
int direction = rot < 0 ? -1 : 1;
34+
for (int i = 0; i < std::abs(rot); ++i) {
35+
dial += direction;
36+
dial %= 100;
37+
if (dial == 0) {
38+
++part2;
39+
}
40+
}
41+
}
42+
std::cout << part2 << "\n";
43+
3044
return 0;
3145
}

0 commit comments

Comments
 (0)