diff --git a/day10/input.txt b/day10/input.txt new file mode 100644 index 0000000..a9a6382 --- /dev/null +++ b/day10/input.txt @@ -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 diff --git a/day10/proci b/day10/proci new file mode 100755 index 0000000..2dc1a07 Binary files /dev/null and b/day10/proci differ diff --git a/day10/proci.c b/day10/proci.c new file mode 100644 index 0000000..1a2fdf3 --- /dev/null +++ b/day10/proci.c @@ -0,0 +1,62 @@ +#include +#include +#include + +#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); +}