Skip to content

Commit

Permalink
Add part 2 outline
Browse files Browse the repository at this point in the history
  • Loading branch information
mjalkio committed Dec 28, 2023
1 parent 431aa8b commit 2fae39e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions year_2023/day09/mirage_maintenance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from util import read_puzzle_input


def sum_extrapolated_values(puzzle_input):
def sum_extrapolated_values(puzzle_input, backwards=False):
histories = puzzle_input.split("\n")
extrapolated_sum = 0
for hist in histories:
Expand All @@ -15,7 +15,7 @@ def sum_extrapolated_values(puzzle_input):
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

Expand All @@ -24,4 +24,4 @@ def sum_extrapolated_values(puzzle_input):
puzzle_input = read_puzzle_input()

print(f"Part 1: {sum_extrapolated_values(puzzle_input)}")
print(f"Part 2: {sum_extrapolated_values(puzzle_input)}")
print(f"Part 2: {sum_extrapolated_values(puzzle_input, backwards=True)}")
7 changes: 7 additions & 0 deletions year_2023/day09/test_mirage_maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@

def test_sum_extrapolated_values():
assert sum_extrapolated_values(read_puzzle_input("test_input.txt")) == 114


def test_sum_extrapolated_values_backwards():
assert (
sum_extrapolated_values(read_puzzle_input("test_input.txt"), backwards=True)
== 2
)

0 comments on commit 2fae39e

Please sign in to comment.