summary refs log tree commit diff homepage
path: root/2018
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-03 00:25:08 -0500
committerJune McEnroe <june@causal.agency>2018-12-03 00:25:08 -0500
commit97351c8d5856ce4ecd62324f340bae57add2a2e6 (patch)
tree8dc6ee031bde21e60e8536013aed4c31713e6dcb /2018
parentUn-hardcode width of input in day 2 (diff)
downloadaoc-97351c8d5856ce4ecd62324f340bae57add2a2e6.tar.gz
aoc-97351c8d5856ce4ecd62324f340bae57add2a2e6.zip
Solve day 3 part 1
Diffstat (limited to '')
-rw-r--r--2018/day03.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/2018/day03.c b/2018/day03.c
new file mode 100644
index 0000000..b4544c1
--- /dev/null
+++ b/2018/day03.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+typedef unsigned char byte;
+typedef unsigned uint;
+
+enum { Len = 1000 };
+static byte fabric[Len][Len];
+
+int main() {
+	while (!feof(stdin)) {
+		uint d, x, y, w, h;
+		scanf("#%u @ %u,%u: %ux%u\n", &d, &x, &y, &w, &h);
+		for (uint i = 0; i < w; ++i) {
+			for (uint j = 0; j < h; ++j) {
+				fabric[x + i][y + j]++;
+			}
+		}
+	}
+	uint count = 0;
+	for (uint x = 0; x < Len; ++x) {
+		for (uint y = 0; y < Len; ++y) {
+			if (fabric[x][y] > 1) count++;
+		}
+	}
+	printf("%u\n", count);
+}