File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 11Day 1:
223
3+ 6
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments