day 4, part1 was quick ; I over-complicated part2 and lost time
This commit is contained in:
		
							
								
								
									
										14
									
								
								d04/part1.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								d04/part1.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					L = [l for l in sys.stdin.read().splitlines()]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					R = 0
 | 
				
			||||||
 | 
					for l in L:
 | 
				
			||||||
 | 
					    _, halves = l.split(':')
 | 
				
			||||||
 | 
					    c1, c2 = halves.split('|')
 | 
				
			||||||
 | 
					    s1 = set(map(int,c1.strip().split(' ')))
 | 
				
			||||||
 | 
					    s2 = set(map(int,c2.strip().split(' ')))
 | 
				
			||||||
 | 
					    n = len(s1&s2)
 | 
				
			||||||
 | 
					    if n>0:
 | 
				
			||||||
 | 
					        R+= 1 << (n-1)
 | 
				
			||||||
 | 
					print(R)
 | 
				
			||||||
							
								
								
									
										15
									
								
								d04/part2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								d04/part2.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					L = [[l,1] for l in sys.stdin.read().splitlines()]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for i in range(len(L)):
 | 
				
			||||||
 | 
					    l, k = L[i]
 | 
				
			||||||
 | 
					    _, halves = l.split(':')
 | 
				
			||||||
 | 
					    c1, c2 = halves.split('|')
 | 
				
			||||||
 | 
					    s1 = set(map(int,c1.strip().split(' ')))
 | 
				
			||||||
 | 
					    s2 = set(map(int,c2.strip().split(' ')))
 | 
				
			||||||
 | 
					    n = len(s1&s2)
 | 
				
			||||||
 | 
					    for j in range(n):
 | 
				
			||||||
 | 
					        if i+j+1<len(L):
 | 
				
			||||||
 | 
					            L[i+j+1][1] += k
 | 
				
			||||||
 | 
					print(sum(k for l,k in L))
 | 
				
			||||||
		Reference in New Issue
	
	Block a user