summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-10 01:05:00 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:25 -0500
commitdc6d778aa4c128149a47645d7e1ca343e86d7402 (patch)
treee1f3aea7dfbaead557b647c2c1135af3f5aa449e
parentSolve day 9 part 2 (diff)
downloadaoc-dc6d778aa4c128149a47645d7e1ca343e86d7402.tar.gz
aoc-dc6d778aa4c128149a47645d7e1ca343e86d7402.zip
Solve day 10 part 1
Diffstat (limited to '')
-rw-r--r--2018/day10.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/2018/day10.c b/2018/day10.c
new file mode 100644
index 0000000..b7044c5
--- /dev/null
+++ b/2018/day10.c
@@ -0,0 +1,43 @@
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+struct Point {
+	int x, y;
+	int dx, dy;
+};
+
+int main() {
+	size_t len = 0;
+	struct Point points[500];
+	while (!feof(stdin)) {
+		scanf(
+			"position=<%d, %d> velocity=<%d, %d>\n",
+			&points[len].x, &points[len].y, &points[len].dx, &points[len].dy
+		);
+		len++;
+	}
+	int minX, minY, maxX, maxY;
+	do {
+		minX = minY = INT_MAX;
+		maxX = maxY = INT_MIN;
+		for (size_t i = 0; i < len; ++i) {
+			points[i].x += points[i].dx;
+			points[i].y += points[i].dy;
+			if (points[i].x < minX) minX = points[i].x;
+			if (points[i].y < minY) minY = points[i].y;
+			if (points[i].x > maxX) maxX = points[i].x;
+			if (points[i].y > maxY) maxY = points[i].y;
+		}
+	} while (maxY - minY > 9);
+	for (int y = minY; y <= maxY; ++y) {
+		for (int x = minX; x <= maxX; ++x) {
+			size_t i;
+			for (i = 0; i < len; ++i) {
+				if (points[i].x == x && points[i].y == y) break;
+			}
+			printf("%c", (i == len ? '.' : '#'));
+		}
+		printf("\n");
+	}
+}