summaryrefslogtreecommitdiff
path: root/2022/day10/main.c
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2022-12-17 16:28:03 +0100
committerOrangerot <purple@orangerot.dev>2022-12-17 16:28:03 +0100
commit0537a2bae5230485e7d0be9569617ae12bba223a (patch)
tree2c1a0214b94bf76cd4ce5361e79941303c9c05e3 /2022/day10/main.c
parent7dff2d8d945b91973e21c1e5f2f9db679052b88e (diff)
day10
Diffstat (limited to '2022/day10/main.c')
-rw-r--r--2022/day10/main.c33
1 files changed, 33 insertions, 0 deletions
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);
+}