Day10
This commit is contained in:
140
day10/input.txt
Normal file
140
day10/input.txt
Normal file
@@ -0,0 +1,140 @@
|
||||
addx 1
|
||||
addx 4
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx 5
|
||||
addx 2
|
||||
addx 1
|
||||
noop
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
noop
|
||||
addx 3
|
||||
noop
|
||||
addx -40
|
||||
noop
|
||||
addx 38
|
||||
addx -31
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
addx -7
|
||||
addx 8
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx 3
|
||||
addx -2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx -36
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
addx 8
|
||||
addx -5
|
||||
addx 5
|
||||
addx 2
|
||||
addx -15
|
||||
addx 16
|
||||
addx 4
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
addx 4
|
||||
addx 5
|
||||
addx -30
|
||||
addx 35
|
||||
addx -1
|
||||
addx 2
|
||||
addx -36
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
addx -2
|
||||
addx 5
|
||||
addx 2
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
addx 14
|
||||
addx -13
|
||||
addx 5
|
||||
addx -14
|
||||
addx 18
|
||||
addx 3
|
||||
addx 2
|
||||
addx -2
|
||||
addx 5
|
||||
addx -40
|
||||
noop
|
||||
addx 32
|
||||
addx -25
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
addx 3
|
||||
addx -2
|
||||
addx 2
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 5
|
||||
addx 2
|
||||
addx 9
|
||||
addx -36
|
||||
addx 30
|
||||
addx 5
|
||||
addx 2
|
||||
addx -25
|
||||
addx 26
|
||||
addx -38
|
||||
addx 10
|
||||
addx -3
|
||||
noop
|
||||
noop
|
||||
addx 22
|
||||
addx -16
|
||||
addx -1
|
||||
addx 5
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
addx -20
|
||||
addx 21
|
||||
addx 3
|
||||
addx 2
|
||||
addx -24
|
||||
addx 28
|
||||
noop
|
||||
addx 5
|
||||
addx 3
|
||||
noop
|
||||
addx -24
|
||||
noop
|
||||
BIN
day10/proci
Executable file
BIN
day10/proci
Executable file
Binary file not shown.
62
day10/proci.c
Normal file
62
day10/proci.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BUFFER_SIZE 64
|
||||
#define INTERESTING_CYCLES 20, 60, 100, 140, 180, 220
|
||||
#define CRT_WIDTH 40
|
||||
#define CRT_HEIGHT 6
|
||||
|
||||
int main() {
|
||||
char buf[BUFFER_SIZE], *p, c;
|
||||
memset(buf, 0, BUFFER_SIZE);
|
||||
p = buf;
|
||||
|
||||
int X = 1, cycle = 0, sum = 0, add, delay = 0;
|
||||
int interesting_cycles[] = {INTERESTING_CYCLES};
|
||||
int row =0, col = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
|
||||
|
||||
if (sscanf(buf, "addx %i", &add)) {
|
||||
delay = 2;
|
||||
} else {
|
||||
add = 0;
|
||||
delay = 1;
|
||||
}
|
||||
|
||||
while (delay > 0) {
|
||||
cycle++;
|
||||
if (col == CRT_WIDTH) {
|
||||
printf("\n");
|
||||
col = 0;
|
||||
row++;
|
||||
}
|
||||
if (X - 1 == col || X == col || X + 1 == col) {
|
||||
printf("#");
|
||||
} else {
|
||||
printf(".");
|
||||
}
|
||||
// Update sum if we are in the right cycle
|
||||
for (int i = 0; i < sizeof(interesting_cycles)/sizeof(int); i++) {
|
||||
if (interesting_cycles[i] == cycle) {
|
||||
sum += X * cycle;
|
||||
}
|
||||
}
|
||||
|
||||
col++;
|
||||
delay--;
|
||||
}
|
||||
|
||||
X += add;
|
||||
|
||||
memset(buf, 0, BUFFER_SIZE);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n%i\n", sum);
|
||||
}
|
||||
Reference in New Issue
Block a user