From 0537a2bae5230485e7d0be9569617ae12bba223a Mon Sep 17 00:00:00 2001 From: Orangerot Date: Sat, 17 Dec 2022 16:28:03 +0100 Subject: day10 --- 2022/day10/main.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 2022/day10/main.c (limited to '2022/day10/main.c') 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 +#include + +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); +} -- cgit v1.2.3