add: part1
This commit is contained in:
parent
222eff07d2
commit
eb95c2147e
3
2023/day09/example1.txt
Normal file
3
2023/day09/example1.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
0 3 6 9 12 15
|
||||||
|
1 3 6 10 15 21
|
||||||
|
10 13 16 21 30 45
|
32
2023/day09/src/part1.py
Normal file
32
2023/day09/src/part1.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
text: str = open("input.txt", "r").read()
|
||||||
|
|
||||||
|
_value: int = 0
|
||||||
|
|
||||||
|
lines = text.splitlines()
|
||||||
|
|
||||||
|
def get_difference(values: [int]):
|
||||||
|
lst = []
|
||||||
|
for i in range(0, len(values) - 1):
|
||||||
|
lst.append(values[i + 1] - values[i])
|
||||||
|
return lst
|
||||||
|
|
||||||
|
def get_next(derives: [[int]]):
|
||||||
|
value = 0
|
||||||
|
for values in derives[::-1]:
|
||||||
|
if (len(values) == 0):
|
||||||
|
continue
|
||||||
|
value = values[-1] + value
|
||||||
|
return value
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
values = list(map(int, line.split()))
|
||||||
|
derives: [[int]] = [values]
|
||||||
|
lst = values
|
||||||
|
while True:
|
||||||
|
lst = get_difference(lst)
|
||||||
|
derives.append(lst)
|
||||||
|
if (lst.count(0) == len(lst)):
|
||||||
|
break
|
||||||
|
_value += get_next(derives)
|
||||||
|
|
||||||
|
print(_value)
|
Loading…
Reference in New Issue
Block a user