parent
874254c1b6
commit
44c0a9d206
1 changed files with 45 additions and 2 deletions
@ -1,9 +1,52 @@ |
||||
#include "Day10.h" |
||||
|
||||
Result Day10::Task1() { |
||||
return Day::Task1(); |
||||
int sum = 0; |
||||
int R = 1; |
||||
int cycle = 1; |
||||
for (const string &line : input){ |
||||
int count = 1; |
||||
int add = 0; |
||||
if (line.starts_with("addx")){ |
||||
add = stoi(line.substr(5)); |
||||
count = 2; |
||||
} |
||||
for (int i = 0; i < count; i++){ |
||||
if ((cycle - 20) % 40 == 0){ |
||||
sum += cycle * R; |
||||
} |
||||
cycle++; |
||||
} |
||||
R += add; |
||||
} |
||||
|
||||
return to_string(sum); |
||||
} |
||||
|
||||
Result Day10::Task2() { |
||||
return Day::Task2(); |
||||
string image = "\n"; |
||||
int R = 1; |
||||
int cycle = 0; |
||||
for (const string &line : input){ |
||||
int count = 1; |
||||
int add = 0; |
||||
if (line.starts_with("addx")){ |
||||
add = stoi(line.substr(5)); |
||||
count = 2; |
||||
} |
||||
for (int i = 0; i < count; i++) { |
||||
char pixel = '.'; |
||||
int y = cycle / 40; |
||||
int x = cycle - (y * 40); |
||||
if (x == R || x == R - 1 || x == R + 1) |
||||
pixel = '#'; |
||||
image += pixel; |
||||
cycle++; |
||||
if (cycle % 40 == 0) |
||||
image += "\n"; |
||||
} |
||||
R += add; |
||||
} |
||||
|
||||
return image; |
||||
} |
Loading…
Reference in new issue