-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc2210.cc
73 lines (65 loc) · 947 Bytes
/
aoc2210.cc
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
#include "iostream"
#include "vector"
#include "sstream"
using namespace std;
int main()
{
vector<int> a;
string s;
int r1, n, x, cc, i, ii;
int len, row;
string r2;
while (getline(cin, s))
{
stringstream ss(s);
a.push_back(0);
if (s == "noop")
continue ;
ss >> s >> n;
a.push_back(n);
}
// part 1
r1 = 0;
x = 1; // X
i = 0;
len = (int) a.size();
cc = 0; // cycle
while (1)
{
if (i == len)
i %= len;
n = a[i];
ii = i + 1;
if (ii == 20 || ii % 40 == 20)
r1 += ii * x;
x += n;
++i;
++cc;
if (cc == 220)
break ;
}
// part 2
x = 1;
i = 0;
cc = 0;
r2 = "\n";
while (1)
{
if (i == len)
i %= len;
row = i % 40;
if (row == x - 1 || row == x || row == x + 1)
r2 += '@';
else
r2 += ' ';
if (!((i + 1) % 40))
r2 += '\n';
x += a[i];
++i;
++cc;
if (cc == 240) // (?)
break ;
}
cout << "Star 1: " << r1 << endl;
cout << "Star 2: " << r2 << endl;
}