Skip to content

Commit

Permalink
Solve day 9 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mjalkio committed Dec 28, 2023
1 parent 6282729 commit 431aa8b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion year_2023/day09/mirage_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@


def sum_extrapolated_values(puzzle_input):
return 0
histories = puzzle_input.split("\n")
extrapolated_sum = 0
for hist in histories:
hist = [int(val) for val in hist.split(" ")]
sequences = [hist]
while any(num != 0 for num in sequences[-1]):
values = sequences[-1]
differences = [values[i + 1] - values[i] for i in range(len(values) - 1)]
sequences.append(differences)

sequences[-1].append(0)
for i in reversed(range(len(sequences) - 1)):
sequences[i].append(sequences[i][-1] + sequences[i + 1][-1])

extrapolated_sum += sequences[0][-1]
return extrapolated_sum


if __name__ == "__main__":
Expand Down

0 comments on commit 431aa8b

Please sign in to comment.