diff options
author | June McEnroe <june@causal.agency> | 2018-12-06 14:56:52 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-12-06 14:56:52 -0500 |
commit | e3e25d17b1cc63088141f4e0d5aa9388c0a36a8e (patch) | |
tree | aa5c6c07f350464015ef783b483d6bbe14968a0a | |
parent | Solve day 5 part 2 (diff) | |
download | aoc-e3e25d17b1cc63088141f4e0d5aa9388c0a36a8e.tar.gz aoc-e3e25d17b1cc63088141f4e0d5aa9388c0a36a8e.zip |
Solve day 6 part 1
-rw-r--r-- | 2018/day06.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/2018/day06.c b/2018/day06.c new file mode 100644 index 0000000..5b9552d --- /dev/null +++ b/2018/day06.c @@ -0,0 +1,52 @@ +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> + +static int len; +static struct Point { + int x, y; +} points[50]; +static int area[50]; + +static int dist(struct Point a, struct Point b) { + int x = a.x - b.x; + int y = a.y - b.y; + return (x < 0 ? -x : x) + (y < 0 ? -y : y); +} + +static int close(struct Point p) { + int c = 0; + for (int i = 1; i < len; ++i) { + if (dist(p, points[i]) < dist(p, points[c])) c = i; + } + for (int i = 0; i < len; ++i) { + if (dist(p, points[i]) == dist(p, points[c]) && i != c) return -1; + } + return c; +} + +int main() { + while (!feof(stdin)) { + scanf("%d, %d\n", &points[len].x, &points[len].y); + len++; + } + int maxX = 0, maxY = 0; + for (int i = 0; i < len; ++i) { + if (points[i].x > maxX) maxX = points[i].x; + if (points[i].y > maxY) maxY = points[i].y; + } + for (int x = 0; x <= maxX; ++x) { + for (int y = 0; y <= maxY; ++y) { + int c = close((struct Point) { x, y }); + if (c < 0) continue; + if (area[c] < 0) continue; + area[c]++; + if (x == 0 || x == maxX || y == 0 || y == maxY) area[c] = -1; + } + } + int max = 0; + for (int i = 0; i < len; ++i) { + if (area[i] > max) max = area[i]; + } + printf("%d\n", max); +} |