This commit is contained in:
Orangerot 2022-12-17 16:28:03 +01:00
parent 7dff2d8d94
commit 0537a2bae5
4 changed files with 363 additions and 0 deletions

146
2022/day10/input1.txt Normal file
View file

@ -0,0 +1,146 @@
addx 15
addx -11
addx 6
addx -3
addx 5
addx -1
addx -8
addx 13
addx 4
noop
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx -35
addx 1
addx 24
addx -19
addx 1
addx 16
addx -11
noop
noop
addx 21
addx -15
noop
noop
addx -3
addx 9
addx 1
addx -3
addx 8
addx 1
addx 5
noop
noop
noop
noop
noop
addx -36
noop
addx 1
addx 7
noop
noop
noop
addx 2
addx 6
noop
noop
noop
noop
noop
addx 1
noop
noop
addx 7
addx 1
noop
addx -13
addx 13
addx 7
noop
addx 1
addx -33
noop
noop
noop
addx 2
noop
noop
noop
addx 8
noop
addx -1
addx 2
addx 1
noop
addx 17
addx -9
addx 1
addx 1
addx -3
addx 11
noop
noop
addx 1
noop
addx 1
noop
noop
addx -13
addx -19
addx 1
addx 3
addx 26
addx -30
addx 12
addx -1
addx 3
addx 1
noop
noop
noop
addx -9
addx 18
addx 1
addx 2
noop
noop
addx 9
noop
noop
noop
addx -1
addx 2
addx -37
addx 1
addx 3
noop
addx 15
addx -21
addx 22
addx -6
addx 1
noop
addx 2
addx 1
noop
addx -10
noop
noop
addx 20
addx 1
addx 2
addx 2
addx -6
addx -11
noop
noop
noop

144
2022/day10/input2.txt Normal file
View file

@ -0,0 +1,144 @@
noop
noop
noop
addx 6
addx -1
addx 5
noop
noop
noop
addx 5
addx -8
addx 9
addx 3
addx 2
addx 4
addx 3
noop
addx 2
noop
addx 1
addx 6
noop
noop
noop
addx -39
noop
addx 5
addx 2
addx -2
addx 3
addx 2
addx 5
addx 2
addx 2
addx 13
addx -12
noop
addx 7
noop
addx 2
addx 3
noop
addx -25
addx 30
addx -10
addx 13
addx -40
noop
addx 5
addx 2
addx 3
noop
addx 2
addx 3
addx -2
addx 3
addx -1
addx 7
noop
noop
addx 5
addx -1
addx 6
noop
noop
noop
noop
addx 9
noop
addx -1
noop
addx -39
addx 2
addx 33
addx -29
addx 1
noop
addx 4
noop
noop
noop
addx 3
addx 2
noop
addx 3
noop
noop
addx 7
addx 2
addx 3
addx -2
noop
addx -30
noop
addx 40
addx -2
addx -38
noop
noop
noop
addx 5
addx 5
addx 2
addx -9
addx 5
addx 7
addx 2
addx 5
addx -18
addx 28
addx -7
addx 2
addx 5
addx -28
addx 34
addx -3
noop
addx 3
addx -38
addx 10
addx -3
addx 29
addx -28
addx 2
noop
noop
noop
addx 5
noop
addx 3
addx 2
addx 7
noop
addx -2
addx 5
addx 2
noop
addx 1
addx 5
noop
noop
addx -25
noop
noop

33
2022/day10/main.c Normal file
View file

@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *line = NULL;
size_t len;
int ops = 1;
int x = 1;
int signal = 0;
while (getline(&line, &len, stdin) != -1)
{
if ((ops+20) % 40 == 0) {
printf("%d %d\n", ops, x);
signal += ops * x;
}
if (line[0] == 'a') {
ops++;
if ((ops+20) % 40 == 0) {
printf("%d %d\n", ops, x);
signal += ops * x;
}
int a = atoi(line+5);
x += a;
printf("%d\n", a);
}
ops++;
}
printf("%d\n", signal);
}

40
2022/day10/main2.c Normal file
View file

@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
void draw(int ops, int x)
{
if ( (ops) % 40 <= x + 2 && (ops) % 40 >= x )
{
printf("#");
} else {
printf(".");
}
if ((ops) % 40 == 0) {
printf("\n");
}
}
int main()
{
char *line = NULL;
size_t len;
int ops = 1;
int x = 1;
int signal = 0;
while (getline(&line, &len, stdin) != -1)
{
draw(ops, x);
if (line[0] == 'a') {
ops++;
draw(ops, x);
int a = atoi(line+5);
x += a;
// printf("%d\n", a);
}
ops++;
}
printf("%d\n", signal);
}