Finished 2023-12-09 p1
This commit is contained in:
parent
5d6ae75477
commit
7b4c3e3536
27
2023/day9/part1.py
Normal file
27
2023/day9/part1.py
Normal file
@ -0,0 +1,27 @@
|
||||
import sys
|
||||
from pprint import pprint
|
||||
from functools import reduce
|
||||
|
||||
maps = []
|
||||
|
||||
with open(sys.argv[1]) as file:
|
||||
for line in file:
|
||||
maps.append([int(x) for x in line.rstrip().split(' ')])
|
||||
|
||||
def calc(line):
|
||||
diff = []
|
||||
for i in range(0,len(line)-1):
|
||||
diff.append(line[i+1]-line[i])
|
||||
if not all(v == 0 for v in diff):
|
||||
last.append(diff[-1])
|
||||
calc(diff)
|
||||
return 0
|
||||
result = []
|
||||
for mdx,m in enumerate(maps):
|
||||
last = []
|
||||
last.append(m[-1])
|
||||
last.append(calc(m))
|
||||
result.append(reduce(lambda x, y: x+y, last))
|
||||
|
||||
print(sum(result))
|
||||
|
1
2023/day9/t2
Normal file
1
2023/day9/t2
Normal file
@ -0,0 +1 @@
|
||||
0 3 6 9 12 15
|
Loading…
Reference in New Issue
Block a user