summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-11 18:16:01 -0500
committerJune McEnroe <june@causal.agency>2019-12-11 18:16:01 -0500
commit24c19b12dc9054a056fe46d6aa551578071c75b6 (patch)
tree05c7b5c80fa8843fd25bbde0f4aa73b5b3c3ae28
parentSolve day 7 part 2 (diff)
downloadaoc-24c19b12dc9054a056fe46d6aa551578071c75b6.tar.gz
aoc-24c19b12dc9054a056fe46d6aa551578071c75b6.zip
Solve day 8 part 1
-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);
+}