40 lines
782 B
Python
40 lines
782 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
data = []
|
|
# parse input
|
|
input_file = open("input", "r")
|
|
for line in input_file:
|
|
line = line.strip()
|
|
if line == "":
|
|
continue
|
|
numbers = []
|
|
for n in line.split():
|
|
numbers.append(int(n))
|
|
data.append(numbers)
|
|
input_file.close()
|
|
|
|
# for d in data:
|
|
# print(d)
|
|
|
|
|
|
def find_diff(val_list):
|
|
if val_list.count(0) == len(val_list):
|
|
return 0
|
|
new_list = []
|
|
for i in range(len(val_list)-1):
|
|
new_list.append(val_list[i+1]-val_list[i])
|
|
# print(val_list, " ", new_list)
|
|
next_val = val_list[0]-find_diff(new_list)
|
|
# print(next_val)
|
|
return next_val
|
|
|
|
|
|
solution = 0
|
|
for d in data:
|
|
temp = find_diff(d)
|
|
print(temp)
|
|
solution += temp
|
|
|
|
print("Lösung:", solution)
|