day 9, refactor
This commit is contained in:
		
							
								
								
									
										11
									
								
								d09/part1.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								d09/part1.py
									
									
									
									
									
								
							@@ -1,11 +0,0 @@
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
L = [list(map(int,l.split(' '))) for l in sys.stdin.read().splitlines()]
 | 
			
		||||
 | 
			
		||||
def extrapolate(L):
 | 
			
		||||
    if all(not a for a in L):
 | 
			
		||||
        return L+[0]
 | 
			
		||||
    M = [b-a for a,b in zip(L,L[1:])]
 | 
			
		||||
    return L+[L[-1]+extrapolate(M)[-1]]
 | 
			
		||||
 | 
			
		||||
print(sum(extrapolate(l)[-1] for l in L))
 | 
			
		||||
							
								
								
									
										11
									
								
								d09/part2.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								d09/part2.py
									
									
									
									
									
								
							@@ -1,11 +0,0 @@
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
L = [list(map(int,l.split(' '))) for l in sys.stdin.read().splitlines()]
 | 
			
		||||
 | 
			
		||||
def extrapolate(L):
 | 
			
		||||
    if all(not a for a in L):
 | 
			
		||||
        return [0]+L
 | 
			
		||||
    M = [b-a for a,b in zip(L,L[1:])]
 | 
			
		||||
    return [L[0]-extrapolate(M)[0]]+L
 | 
			
		||||
 | 
			
		||||
print(sum(extrapolate(l)[0] for l in L))
 | 
			
		||||
							
								
								
									
										12
									
								
								d09/run.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								d09/run.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
L = [list(map(int,l.split(' '))) for l in sys.stdin.read().splitlines()]
 | 
			
		||||
 | 
			
		||||
def extrapolate(L):
 | 
			
		||||
    if all(a == 0 for a in L):
 | 
			
		||||
        return 0
 | 
			
		||||
    M = [b-a for a,b in zip(L,L[1:])]
 | 
			
		||||
    return L[-1]+extrapolate(M)
 | 
			
		||||
 | 
			
		||||
print(sum(extrapolate(l) for l in L))
 | 
			
		||||
print(sum(extrapolate(l[::-1]) for l in L))
 | 
			
		||||
		Reference in New Issue
	
	Block a user