-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday10.cpp
71 lines (52 loc) · 1.21 KB
/
day10.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
using namespace std;
#include <iostream>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include "Helpers/HelperFunctions.h"
int main() {
cout << "Day 10" << endl;
ifstream file(R"(C:\Users\gwen\Documents\2_Programming\Advent of Code\Advent of Code 2022\inputs\day10.txt)");
string str;
vector<string> data;
while (getline(file, str)) {
data.push_back(str);
}
int cycle = 1;
int val = 1;
long sum = 0;
vector<string> screen(6, "");
auto it = data.begin();
bool addx = false;
while (it != data.end()) {
int target = floor((cycle - 1) / 40);
int position = (cycle - 1) % 40;
if (val - 1 <= position && position <= val + 1) {
screen[target].push_back('#');
} else {
screen[target].push_back('.');
}
if (((cycle - 20) % 40 == 0) && (cycle < 221)) {
sum += cycle * val;
}
if (addx) {
val+= stoi(it->substr(5));
it++;
addx = false;
} else if (*it == "noop") {
it++;
} else {
addx = true;
}
cycle++;
}
cout << "Part 1: " << sum << endl;
cout << "Part 2: " << endl;
for (auto &crt : screen) {
cout << crt << endl;
}
return 0;
}