Day 9
This commit is contained in:
1 parent
101cc2c706
commit
62dd0c0e52
4 files changed
+333
No files matched your search
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
oasis = [[int(n) for n in line.strip('\n').split(' ')] for line in open(sys.argv[1])]
|
||||
|
||||
res1, res2 = 0, 0
|
||||
for row in oasis:
|
||||
array = []
|
||||
array.append(deepcopy(row))
|
||||
for i in range(len(row)):
|
||||
array.append([])
|
||||
for k,v in enumerate(array[i][1:]):
|
||||
array[i+1].append(v - array[i][k])
|
||||
# challenge 1
|
||||
res1 += array[i][-1]
|
||||
if sum(array[i+1]) == 0: break
|
||||
# challenge 2
|
||||
p = 0
|
||||
for a in reversed(array):
|
||||
p = a[0] - p
|
||||
res2 += p
|
||||
|
||||
res1 = str(res1)
|
||||
print(f"challenge 1:\n{res1}\n")
|
||||
|
||||
res2 = str(res2)
|
||||
print(f"challenge 2:\n{res2}\n")
|
||||
|
||||
Reference in new issue
Block a user