+/AoC

advent of code

git clone https://git.julia.blue/+/AoC

Julia RyanDay 23de00e15

master
809 B33 linesraw
1from collections import defaultdict
2from itertools import combinations
3
4with open("input") as f:
5    raw = f.read()
6
7con = defaultdict(set)
8for line in raw.splitlines():
9    l, r = line.split("-")
10    con[l].add(r)
11    con[r].add(l)
12con = {k: v | {k} for k, v in con.items()}
13
14
15threes = set()
16for g in con.values():
17    for c in combinations(g, 3):
18        if all(set(c) <= con[machine] for machine in c) and any(
19            machine.startswith("t") for machine in c
20        ):
21            threes.add(tuple(sorted(c)))
22print(len(threes))
23
24
25def biggest(g):
26    for n in range(4, len(g))[::-1]:
27        for c in combinations(g, n):
28            if all(set(c) <= con[machine] for machine in c):
29                return c
30    return set()
31
32
33print(",".join(sorted(max([biggest(g) for g in con.values()], key=len))))