summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-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);
+}