summary refs log tree commit diff homepage
path: root/2019/day08.c
blob: 4ddbc60db6167b6941921e2f4bf72ca926b9b45d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#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);

	char img[6][25];
	for (size_t l = len - 1; l < len; --l) {
		for (int y = 0; y < 6; ++y) {
			for (int x = 0; x < 25; ++x) {
				switch (layers[l][y][x]) {
					break; case '0': img[y][x] = '.';
					break; case '1': img[y][x] = '#';
				}
			}
		}
	}
	for (int y = 0; y < 6; ++y) {
		printf("%.*s\n", 25, img[y]);
	}
}
53995a4478747f6c12e00c01cbb34705&follow=1'>Implement 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