aoc2024/d23/part2_set.py

17 lines
388 B
Python
Raw Normal View History

2024-12-24 01:03:04 +00:00
import sys
from collections import defaultdict as DD
from itertools import combinations as comb
D = DD(set)
for i in sys.stdin.read().strip().split('\n'):
a, b = i.split("-")
D[a].add(b)
D[b].add(a)
for k, v in D.items():
for i in v:
w = v - {i}
if all(b in D[a] for a,b in comb(w,2)):
print(",".join(sorted({k}|w)))
#sys.exit(0)