summary refs log tree commit diff homepage
path: root/2018/day23.c
blob: dca2a0b235ed7c668f395eb1238e8f5f5a11a9aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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);
}
'/litterbox/commit/litterbox.c?id=b9afd7f8f8bbb799ec3e2f6c18edca1593c2c61b&follow=1'>Log bans and unbansJune McEnroe 2020-04-05Parse mode types from ISUPPORTJune McEnroe 2020-04-05Add unscoop matchers for ban/unban eventsJune McEnroe 2020-04-05Check unscoop regexps with make testJune McEnroe 2020-04-05Add unscoop -n flag for checking regexpsJune McEnroe 2020-04-05Add Ban and Unban event typesJune McEnroe 2020-04-02Update styleJune McEnroe 2020-03-31Update unscoop catgirl matchersJune McEnroe 2020-03-31Fix writing verbose to stderrJune McEnroe 2020-03-02Include <>/-/* around nicks in scoop coloring 1.1June McEnroe 2020-03-02Replace .mk files with configure scriptJune McEnroe 2020-02-28Implement the causal.agency/consumer capabilityJune McEnroe 2020-02-22Include <>/-/* around nicks in coloringJune McEnroe 2020-02-22Use (almost) the full range of IRC colors for nicksJune McEnroe