summary refs log tree commit diff homepage
path: root/2018
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-12-23 12:46:17 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:14:26 -0500
commitd0b44f9e61322b05546d8af7840f721d4459393b (patch)
treecbc90e02afc564eab8ff7bfd3f9863bd35b11aa8 /2018
parentSolve day 22 part 1 (diff)
downloadaoc-d0b44f9e61322b05546d8af7840f721d4459393b.tar.gz
aoc-d0b44f9e61322b05546d8af7840f721d4459393b.zip
Solve day 23 part 1
Diffstat (limited to '2018')
-rw-r--r--2018/day23.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/2018/day23.c b/2018/day23.c
new file mode 100644
index 0000000..dca2a0b
--- /dev/null
+++ b/2018/day23.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+typedef unsigned uint;
+
+struct Point {
+	int x, y, z;
+};
+
+static int distance(struct Point a, struct Point b) {
+	int x = (a.x > b.x ? a.x - b.x : b.x - a.x);
+	int y = (a.y > b.y ? a.y - b.y : b.y - a.y);
+	int z = (a.z > b.z ? a.z - b.z : b.z - a.z);
+	return x + y + z;
+}
+
+struct Bot {
+	struct Point pos;
+	int radius;
+};
+
+int main(void) {
+	uint len = 0;
+	struct Bot bots[1000];
+	while (!feof(stdin)) {
+		scanf(
+			"pos=<%d,%d,%d>, r=%d\n",
+			&bots[len].pos.x, &bots[len].pos.y, &bots[len].pos.z,
+			&bots[len].radius
+		);
+		len++;
+	}
+
+	uint max, maxRadius = 0;
+	for (uint i = 0; i < len; ++i) {
+		if (bots[i].radius < maxRadius) continue;
+		max = i;
+		maxRadius = bots[i].radius;
+	}
+
+	uint inRange = 0;
+	for (uint i = 0; i < len; ++i) {
+		if (distance(bots[i].pos, bots[max].pos) > bots[max].radius) continue;
+		inRange++;
+	}
+	printf("%u\n", inRange);
+}