09-2 fertig
This commit is contained in:
39
09/09-1.py
39
09/09-1.py
@@ -0,0 +1,39 @@
|
|||||||
|
#!/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[len(val_list)-1]+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)
|
||||||
|
|||||||
39
09/09-2.py
Normal file
39
09/09-2.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/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)
|
||||||
Reference in New Issue
Block a user