solve.py (1052B)
1import sys 2sys.path.append("../common") 3import aoc 4 5def parse_entry(l): 6 return [int(v) for v in l.split(",")] 7 8coordinates = [parse_entry(l) for l in aoc.data.split("\n") if len(l) != 0] 9 10def dist(c1, c2): 11 return sum([abs(c1[i] - c2[i]) for i in range(4)]) 12 13def get_close(coords, c): 14 match = list() 15 j = 0 16 while j in range(len(coords)): 17 if dist(c, coords[j]) <= 3: 18 match.append(coords[j]) 19 coords.pop(j) 20 else: 21 j += 1 22 return match 23 24""" 25sum = 0 26for cons in constellations: 27 sum += len(cons) 28print(sum) 29""" 30 31def solve1(args): 32 constellations = list() 33 available = coordinates[:] 34 35 while len(available) != 0: 36 match = get_close(available, available[0]) 37 38 j = 0 39 while j < len(match): 40 match += get_close(available, match[j]) 41 j += 1 42 43 constellations.append(match) 44 45 return len(constellations) 46 47def solve2(args): 48 return "" 49 50aoc.run(solve1, solve2, sols=[386, ""])