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