diff --git a/d23/part1.py b/d23/part1.py new file mode 100644 index 0000000..d16b443 --- /dev/null +++ b/d23/part1.py @@ -0,0 +1,18 @@ +import sys +from collections import defaultdict as DD + +D = DD(set) +for i in sys.stdin.read().strip().split('\n'): + a, b = i.split("-") + D[a].add(b) + D[b].add(a) + +ans = 0 +for (a,B) in D.items(): + for b in B: + for c in D[b]: + for d in D[c]: + if d == a and a!=b and b!=c and c!=a and (a.startswith("t") or b.startswith("t")or c.startswith("t")): + ans += 1 +print(ans//6) + diff --git a/d23/part2_naive.py b/d23/part2_naive.py new file mode 100644 index 0000000..6d7ad38 --- /dev/null +++ b/d23/part2_naive.py @@ -0,0 +1,36 @@ +import sys +from collections import defaultdict as DD + + +D = DD(set) +S = set() +for i in sys.stdin.read().strip().split('\n'): + a, b = i.split("-") + D[a].add(b) + D[b].add(a) + S.add(a) + S.add(b) + +G = set() +m = 0 +def grow(group:set[str], l:int): + global m + key = ','.join(sorted(group)) + if key in G: + return + G.add(key) + if l>m: + print(l, key) + m = l + rest = S - group + for r in rest: + if len(group & D[r]) == l: + ng = group.copy() + ng.add(r) + yield (l+1, ng) + yield from grow(ng, l+1) + +for a, B in D.items(): + for b in B: + for i,s in grow({a,b},2): + pass diff --git a/d23/part2_set.py b/d23/part2_set.py new file mode 100644 index 0000000..ec0cf31 --- /dev/null +++ b/d23/part2_set.py @@ -0,0 +1,16 @@ +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)