summary refs log tree commit diff homepage
path: root/2018
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-12 01:05:33 -0500
committerJune McEnroe <june@causal.agency>2018-12-12 01:05:33 -0500
commit81f098bcb8b58f0a0d803f3e32e252f72217da3d (patch)
treee025092f4ea94780254d7f29c34fa5466e4078a2 /2018
parentSolve day 11 part 2 (diff)
downloadaoc-81f098bcb8b58f0a0d803f3e32e252f72217da3d.tar.gz
aoc-81f098bcb8b58f0a0d803f3e32e252f72217da3d.zip
Solve day 12 part 1
Diffstat (limited to '2018')
-rw-r--r--2018/day12.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/2018/day12.c b/2018/day12.c
new file mode 100644
index 0000000..5f2f04e
--- /dev/null
+++ b/2018/day12.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef unsigned uint;
+
+enum { Zero = 128, Len = Zero * 2 };
+struct State {
+	char pots[Len];
+};
+
+struct Rule {
+	char pots[5];
+	char next;
+};
+
+int main() {
+	struct State state;
+	memset(state.pots, '.', Len);
+	scanf("initial state: %s\n\n", &state.pots[Zero]);
+	for (uint i = 0; i < Len; ++i) {
+		if (!state.pots[i]) state.pots[i] = '.';
+	}
+
+	uint rulen = 0;
+	struct Rule rules[32];
+	while (!feof(stdin)) {
+		scanf("%5c => %c\n", rules[rulen].pots, &rules[rulen].next);
+		rulen++;
+	}
+
+	for (uint g = 0; g < 20; ++g) {
+		struct State next;
+		memset(next.pots, '.', Len);
+		for (uint i = 2; i < Len - 2; ++i) {
+			for (uint r = 0; r < rulen; ++r) {
+				if (memcmp(&state.pots[i - 2], rules[r].pots, 5)) continue;
+				next.pots[i] = rules[r].next;
+				break;
+			}
+		}
+		state = next;
+	}
+
+	int sum = 0;
+	for (int i = 0; i < Len; ++i) {
+		if (state.pots[i] == '#') sum += i - Zero;
+	}
+	printf("%d\n", sum);
+}
) c8af66ab8ad7cd78557f0f9f5ef6a52fd46ee6dd Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban sprintf()Christian Hesse Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-08-28filters: generate anchor links from markdownChristian Hesse This makes the markdown filter generate anchor links for headings. Signed-off-by: Christian Hesse <mail@eworm.de> Tested-by: jean-christophe manciot <actionmystique@gmail.com> 2018-08-03Bump version.Jason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-08-03clone: fix directory traversalJason A. Donenfeld This was introduced in the initial version of this code, way back when in 2008. $ curl http://127.0.0.1/cgit/repo/objects/?path=../../../../../../../../../etc/passwd root:x:0:0:root:/root:/bin/sh ... Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Jann Horn <jannh@google.com> 2018-08-03config: record repo.snapshot-prefix in the per-repo configKonstantin Ryabitsev