This commit is contained in:
Dobos Ádám
2022-12-11 19:45:46 +01:00
parent 31d9baf8e3
commit bcc2d7d2e9
3 changed files with 202 additions and 0 deletions

140
day10/input.txt Normal file
View 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
View File

Binary file not shown.

62
day10/proci.c Normal file
View 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);
}