summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2019/day05.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/2019/day05.c b/2019/day05.c
new file mode 100644
index 0000000..3b38124
--- /dev/null
+++ b/2019/day05.c
@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+static int input(void) {
+	return 1;
+}
+
+static void output(int x) {
+	printf("%d\n", x);
+}
+
+static int ip;
+static int mem[1024];
+
+static int *p(int mode, int param) {
+	return (mode ? &mem[ip + param] : &mem[mem[ip + param]]);
+}
+
+static void run(void) {
+	while (mem[ip] != 99) {
+		int op = mem[ip] % 100;
+		int m1 = mem[ip] / 100 % 10;
+		int m2 = mem[ip] / 1000 % 10;
+		int m3 = mem[ip] / 10000 % 10;
+		switch (op) {
+			break; case 1: *p(m3, 3) = *p(m1, 1) + *p(m2, 2); ip += 4;
+			break; case 2: *p(m3, 3) = *p(m1, 1) * *p(m2, 2); ip += 4;
+			break; case 3: *p(m1, 1) = input(); ip += 2;
+			break; case 4: output(*p(m1, 1)); ip += 2;
+			break; default: abort();
+		}
+	}
+}
+
+int main(void) {
+	for (int i = 0; EOF != scanf("%d,", &mem[i]); ++i);
+	run();
+}
r> who the fuck is scraeming "#define _GNU_SOURCE" at my house. show yourself, coward. i will never #define _GNU_SOURCE 2019-05-20Fix comparison warning in ttpreJune McEnroe 2019-05-20Add AuthorityJune McEnroe 2019-05-19Specify precedence of unary versions of operatorsJune McEnroe 2019-05-18Add compound assignment operators to orderJune McEnroe 2019-05-15Support simple assignment in orderJune McEnroe 2019-05-15Implement sizeof in orderJune McEnroe 2019-05-15Add orderJune McEnroe 2019-05-12Add T suffix in bitJune McEnroe 2019-05-10Highlight yacc and lex files as CJune McEnroe Their %-prefixed directives should probably be highlighted Macro. 2019-05-10Use val instead of suboptargJune McEnroe suboptarg doesn't exist in GNU. Hopefully BSD getsubopt also sets val on failure? 2019-05-09Add Parable of the SowerJune McEnroe 2019-05-07Add bit without buildJune McEnroe Need to do some stuff in the Makefile for lex and yacc and generating HTML pages for it. 2019-05-04Fix MANDIR typoJune McEnroe 2019-05-04Move relay to binJune McEnroe