-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_21a.cpp
46 lines (41 loc) · 971 Bytes
/
day_21a.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <fstream>
#include <iostream>
#include <string>
int main(int argc, char * argv[]) {
std::string input = "../input/day_21_input";
if (argc > 1) {
input = argv[1];
}
std::string line;
std::fstream file(input);
std::getline(file, line);
int p1 = line[28] - '0';
std::getline(file, line);
int p2 = line[28] - '0';
int score1 = 0;
int score2 = 0;
int n_move = 6;
int count = 0;
int rolls = 0;
while (true) {
p1 += n_move;
p1 = p1 % 10; // let 10 be position 0;
score1 += (p1 == 0 ? 10 : p1); // ensure points added with 10
rolls += 3;
if (score1 >= 1000) {
std::cout << rolls * score2 << '\n';
return 0;
}
n_move += 9;
p2 += n_move;
p2 = p2 % 10; // let 10 be position 0;
score2 += (p2 == 0 ? 10 : p2); // ensure points added with 10
rolls += 3;
if (score2 >= 1000) {
std::cout << rolls * score1 << '\n';
return 0;
}
n_move += 9;
}
return 0;
}