diff options
author | June McEnroe <june@causal.agency> | 2018-12-06 14:56:52 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-11-22 00:14:25 -0500 |
commit | ee96114a9561dbd0ca1f27ee5ec55fef69937fcb (patch) | |
tree | acf5fa0c4a6ffc9717195acbe02dbd7ff3f7532d /2018 | |
parent | Solve day 5 part 2 (diff) | |
download | aoc-ee96114a9561dbd0ca1f27ee5ec55fef69937fcb.tar.gz aoc-ee96114a9561dbd0ca1f27ee5ec55fef69937fcb.zip |
Solve day 6 part 1
Diffstat (limited to '2018')
-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); +} |