File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,15 @@ def step_differences(histories:list) -> list[list[list]]:
22
22
return differences
23
23
24
24
25
- def extrapolate_history (histories :str ) -> list :
25
+ def extrapolate_history (histories :str , reverse : bool = False ) -> list :
26
26
extrapolated = []
27
27
for history in histories :
28
28
value = 0
29
29
for x in range (len (history )- 2 , - 1 , - 1 ):
30
- value += history [x ][- 1 ]
30
+ if reverse :
31
+ value = history [x ][0 ] - value
32
+ else :
33
+ value += history [x ][- 1 ]
31
34
extrapolated .append (value )
32
35
33
36
return extrapolated
@@ -40,3 +43,7 @@ def extrapolate_history(histories:str) -> list:
40
43
# Part 1
41
44
extrapolated = extrapolate_history (differences )
42
45
print (f"All the extrapolated values add up to { sum (extrapolated )} " )
46
+
47
+ # Part 2
48
+ extrapolated = extrapolate_history (differences , True )
49
+ print (f"All the previous extrapolated values add up to { sum (extrapolated )} " )
You can’t perform that action at this time.
0 commit comments