blob: 973885a6b7530335316d62a444debe164e4aad80 (
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
48
49
50
|
import sys
sys.path.append("../common")
import aoc
def parse_entry(l):
return [int(v) for v in l.split(",")]
coordinates = [parse_entry(l) for l in aoc.data.split("\n") if len(l) != 0]
def dist(c1, c2):
return sum([abs(c1[i] - c2[i]) for i in range(4)])
def get_close(coords, c):
match = list()
j = 0
while j in range(len(coords)):
if dist(c, coords[j]) <= 3:
match.append(coords[j])
coords.pop(j)
else:
j += 1
return match
"""
sum = 0
for cons in constellations:
sum += len(cons)
print(sum)
"""
def solve1(args):
constellations = list()
available = coordinates[:]
while len(available) != 0:
match = get_close(available, available[0])
j = 0
while j < len(match):
match += get_close(available, match[j])
j += 1
constellations.append(match)
return len(constellations)
def solve2(args):
return ""
aoc.run(solve1, solve2, sols=[386, ""])
|