summary refs log tree commit diff homepage
path: root/2019/day08.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-11 18:16:01 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:26 -0500
commit2c20502210ed6fa503ea051b70e0afd2993c54f4 (patch)
tree7e8161ced02e6a4add4195cb501a3a405d4e536d /2019/day08.c
parentSolve day 7 part 2 (diff)
downloadaoc-2c20502210ed6fa503ea051b70e0afd2993c54f4.tar.gz
aoc-2c20502210ed6fa503ea051b70e0afd2993c54f4.zip
Solve day 8 part 1
Diffstat (limited to '2019/day08.c')
-rw-r--r--2019/day08.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/2019/day08.c b/2019/day08.c
new file mode 100644
index 0000000..05011c8
--- /dev/null
+++ b/2019/day08.c
@@ -0,0 +1,28 @@
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+int main(void) {
+	char layers[128][6][25];
+	size_t len = fread(layers, sizeof(layers[0]), 128, stdin);
+	int min, min0 = INT_MAX;
+	for (int l = 0; l < len; ++l) {
+		int zero = 0;
+		for (int y = 0; y < 6; ++y) {
+			for (int x = 0; x < 25; ++x) {
+				if (layers[l][y][x] == '0') zero++;
+			}
+		}
+		if (zero < min0) {
+			min = l;
+			min0 = zero;
+		}
+	}
+	int one = 0, two = 0;
+	for (int y = 0; y < 6; ++y) {
+		for (int x = 0; x < 25; ++x) {
+			if (layers[min][y][x] == '1') one++;
+			if (layers[min][y][x] == '2') two++;
+		}
+	}
+	printf("%d\n", one * two);
+}