From 431aa8bc42a09fd2dd09fedd38cf0abd4284088d Mon Sep 17 00:00:00 2001 From: Michael Jalkio Date: Thu, 28 Dec 2023 02:53:18 +0000 Subject: [PATCH] Solve day 9 part 1 --- year_2023/day09/mirage_maintenance.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/year_2023/day09/mirage_maintenance.py b/year_2023/day09/mirage_maintenance.py index 0cdf657..5dd38dd 100644 --- a/year_2023/day09/mirage_maintenance.py +++ b/year_2023/day09/mirage_maintenance.py @@ -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__":