diff --git a/Day10/part1.cpp b/Day10/part1.cpp new file mode 100644 index 0000000..bcc85d8 --- /dev/null +++ b/Day10/part1.cpp @@ -0,0 +1,33 @@ +#include +#include + +using namespace std; + +int main(int argc, char* argv[]) +{ + string line; + int cycle = 1; + int accumulator = 1; + int answer = 0; + while(getline(cin, line)) + { + int next_adden = 0; + if (line.substr(0,4).compare("addx") == 0) + { + next_adden = stoi(line.substr(5)); + cycle++; + if ((cycle-20)%40 == 0) + { + answer += cycle*accumulator; + } + accumulator += next_adden; + } + + cycle++; + if ((cycle-20)%40 == 0) + { + answer += cycle*accumulator; + } + } + cout << answer << endl; +} \ No newline at end of file diff --git a/Day10/part2.cpp b/Day10/part2.cpp new file mode 100644 index 0000000..c130d1f --- /dev/null +++ b/Day10/part2.cpp @@ -0,0 +1,50 @@ +#include +#include + +using namespace std; + +int main(int argc, char* argv[]) +{ + string line; + int cycle = 1; + int x = 0; + int accumulator = 1; + while(getline(cin, line)) + { + if (accumulator >= x-1 && accumulator <= x+1) + { + cout << "#"; + } + else + { + cout << " "; + } + cycle++; + x++; + if (0 == x%40) + { + x = 0; + cout << endl; + } + + if (line.substr(0,4).compare("addx") == 0) + { + if (accumulator >= x-1 && accumulator <= x+1) + { + cout << "#"; + } + else + { + cout << " "; + } + accumulator += stoi(line.substr(5)); + cycle++; + x++; + if (0 == x%40) + { + x = 0; + cout << endl; + } + } + } +} \ No newline at end of file