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);
}
ce htagml regex with strncmpJune McEnroe 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe