-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday10b.cpp
75 lines (71 loc) · 1.58 KB
/
day10b.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#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 pixel = 0;
int row = 0;
bool result[6][40]{false};
for (auto &&x : input)
{
if (std::regex_search(x, reg_out, reg_exp))
{
auto change = std::stoi(reg_out[2]);
if (abs(pixel - register_val) <= 1)
{
result[row][pixel] = true;
}
cycle_count++;
pixel++;
if (pixel > 39)
{
pixel = 0;
row++;
}
if (abs(pixel - register_val) <= 1)
{
result[row][pixel] = true;
}
cycle_count++;
pixel++;
if (pixel > 39)
{
pixel = 0;
row++;
}
register_val += change;
}
else
{
if (abs(pixel - register_val) <= 1)
{
result[row][pixel] = true;
}
pixel++;
if (pixel > 39)
{
pixel = 0;
row++;
}
cycle_count++;
}
}
for (auto &&x : result)
{
for (auto &&y : x)
{
if (y)
{
std::cout << "#";
}
else
{
std::cout << ".";
}
}
std::cout << "\n";
}
}