day 22, slow without hint
This commit is contained in:
		
							
								
								
									
										18
									
								
								d23/part1.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								d23/part1.py
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										36
									
								
								d23/part2_naive.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								d23/part2_naive.py
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
							
								
								
									
										16
									
								
								d23/part2_set.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								d23/part2_set.py
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
			
		||||
		Reference in New Issue
	
	Block a user