You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
776 B
32 lines
776 B
#!/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")
|
|
|
|
|