summaryrefslogtreecommitdiff
path: root/2022
diff options
context:
space:
mode:
Diffstat (limited to '2022')
-rw-r--r--2022/day10/input1.txt146
-rw-r--r--2022/day10/input2.txt144
-rw-r--r--2022/day10/main.c33
-rw-r--r--2022/day10/main2.c40
4 files changed, 363 insertions, 0 deletions
diff --git a/2022/day10/input1.txt b/2022/day10/input1.txt
new file mode 100644
index 0000000..37ee8ee
--- /dev/null
+++ b/2022/day10/input1.txt
@@ -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
diff --git a/2022/day10/input2.txt b/2022/day10/input2.txt
new file mode 100644
index 0000000..3d9acd7
--- /dev/null
+++ b/2022/day10/input2.txt
@@ -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
diff --git a/2022/day10/main.c b/2022/day10/main.c
new file mode 100644
index 0000000..c256e11
--- /dev/null
+++ b/2022/day10/main.c
@@ -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);
+}
diff --git a/2022/day10/main2.c b/2022/day10/main2.c
new file mode 100644
index 0000000..c4ef0ae
--- /dev/null
+++ b/2022/day10/main2.c
@@ -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);
+}