day 13, with help
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								d12/result.png
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								d12/result.png
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 80 KiB | 
							
								
								
									
										33
									
								
								d13/run.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								d13/run.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| import sys | ||||
|  | ||||
| P = [ tuple(map(eval, p.split("\n"))) for p in sys.stdin.read().split("\n\n") ] | ||||
|  | ||||
| def C(l,r): | ||||
|     T = (type(l),type(r)) | ||||
|     if T == (int,int): | ||||
|         if l<r: return -1 | ||||
|         return l>r # 0 or 1 | ||||
|     elif T == (int,list): | ||||
|         return C([l],r) | ||||
|     elif T == (list,int): | ||||
|         return C(l,[r]) | ||||
|     else: # list,list | ||||
|         for q in zip(l,r): | ||||
|             c = C(*q) | ||||
|             if c: return c | ||||
|         return C(len(l),len(r)) | ||||
|  | ||||
| # part 1 | ||||
| S = 0 | ||||
| for i,p in enumerate(P): | ||||
|     if C(*p) <= 0: | ||||
|         S += i+1 | ||||
| print(S) | ||||
|  | ||||
| # part 2 | ||||
| from functools import cmp_to_key | ||||
| Q = [ q for (l,r) in P for q in [l,r] ] | ||||
| Q.append([[2]]) | ||||
| Q.append([[6]]) | ||||
| Q.sort(key=cmp_to_key(C)) | ||||
| print((Q.index([[2]])+1)*(Q.index([[6]])+1)) | ||||
		Reference in New Issue
	
	Block a user