day 11, 1 is also 2-1
This commit is contained in:
		
							
								
								
									
										31
									
								
								d11/run.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								d11/run.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					import sys
 | 
				
			||||||
 | 
					from itertools import product as Prod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					L = [list(l) for l in sys.stdin.read().splitlines()]
 | 
				
			||||||
 | 
					H = len(L)
 | 
				
			||||||
 | 
					W = len(L[0])
 | 
				
			||||||
 | 
					RD = {y for y in range(W) if "".join(L[y]).find("#")==-1}
 | 
				
			||||||
 | 
					CD = {x for x in range(H) if all(L[y][x] == '.' for y in range(W))}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					G = [(x,y) 
 | 
				
			||||||
 | 
					for y in range(W)
 | 
				
			||||||
 | 
					    for x in range(H)
 | 
				
			||||||
 | 
					        if L[y][x] == '#']    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					X = float(sys.argv[1])  # expantion factor, 2 for part 1, 1E6 for part 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def exp(a:int,b:int,S:set[int]) -> int:
 | 
				
			||||||
 | 
					    if a > b:
 | 
				
			||||||
 | 
					        b, a = a, b
 | 
				
			||||||
 | 
					    return sum(1 for s in S if a<s<b)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					S = 0
 | 
				
			||||||
 | 
					for i in range(len(G)):
 | 
				
			||||||
 | 
					    for j in range(i+1,len(G)):
 | 
				
			||||||
 | 
					        x1,y1 = G[i]
 | 
				
			||||||
 | 
					        x2,y2 = G[j]
 | 
				
			||||||
 | 
					        ex = exp(x1,x2,CD)
 | 
				
			||||||
 | 
					        ey = exp(y1,y2,RD)
 | 
				
			||||||
 | 
					        d = abs(x2-x1)+abs(y2-y1)+(X-1)*(ex+ey)
 | 
				
			||||||
 | 
					        S += d
 | 
				
			||||||
 | 
					print(int(S))
 | 
				
			||||||
		Reference in New Issue
	
	Block a user