-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday10a.cpp
44 lines (41 loc) · 1.01 KB
/
day10a.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
#include "utils.hpp"
int main(int argc, char *argv[])
{
std::regex reg_exp("([a-z]+) ([-0-9]+)");
std::smatch reg_out;
auto input = read_input("day10_input");
int cycle_count = 0;
int register_val = 1;
int retval = 0;
for (auto &&x : input)
{
if (std::regex_search(x, reg_out, reg_exp))
{
auto change = std::stoi(reg_out[2]);
cycle_count++;
if ((cycle_count % 40) == 20)
{
retval += (cycle_count * register_val);
}
cycle_count++;
if ((cycle_count % 40) == 20)
{
retval += (cycle_count * register_val);
}
register_val += change;
}
else
{
cycle_count++;
if ((cycle_count % 40) == 20)
{
retval += (cycle_count * register_val);
}
}
if (cycle_count > 220)
{
break;
}
}
std::cout << retval << "\n";
}