Skip to content

Commit

Permalink
Solve day 9 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mjalkio committed Dec 28, 2023
1 parent 2fae39e commit 5f4017a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions year_2023/day09/mirage_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ def sum_extrapolated_values(puzzle_input, backwards=False):

sequences[-1].append(0)
for i in reversed(range(len(sequences) - 1)):
sequences[i].append(sequences[i][-1] + sequences[i + 1][-1])
if backwards:
sequences[i].insert(0, (sequences[i + 1][0] - sequences[i][0]) * -1)
else:
sequences[i].append(sequences[i][-1] + sequences[i + 1][-1])

extrapolated_sum += sequences[0][-1]
if backwards:
extrapolated_sum += sequences[0][0]
else:
extrapolated_sum += sequences[0][-1]
return extrapolated_sum


Expand Down

0 comments on commit 5f4017a

Please sign in to comment.