From 7461ab75360130deb7982206cc026c9d4559e774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Sat, 9 Dec 2023 23:53:06 +0100 Subject: [PATCH] Added commentary for a some of the solved puzzles --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index a7f3010..f67d4b7 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,28 @@ Solver for [Advent of Code 2023](https://adventofcode.com/2023/) puzzles. +## Day 1: Trebuchet?! + +My solution parses each line only once to find the right and left numbers for both parts of the puzzle. + +## Day 2: Cube Conundrum + +That one seemed pretty straight forward. For each line, the solution immediately sums up games that fulfill the maxima and finds the maxima of each color. + +## Day 3: Gear Ratios + +For this I modified the solver class to pass in three lines at once, shifting one line down in each iteration, processing the numbers in the middle line and looking for additional symbols in the lines before and after. + +It was a bit tricky to track the data needed for processing of each line and discarding it in time, without resorting to reading all data in before processing. I stumbled over quite a few bugs before making this work. + +## Day 9: Mirage Maintenance + +This one I enjoyed the most so far. The process that is discribed in the puzzle, constructing a series of differences from the previous series, and then reverting the process to extend the series, is equivalent to finding a polynomial with maximum degree of *n - 1*, where the original series are *n* equidistant values of the polynomial. + +So instead of using the outlined "brute force" method, I used Lagrange polynomials with *x1 = 0, x2 = 1, ..., xn = n - 1* evaluated at *x = n* (for part 1) and *x = -1* (for part 2) to find the function values for the extrapolated "points". Conveniently, the Lagrange polynomials can be precalculated (with some tricks to not run over Int64 limits) and make the calculation of the extrapolated values quite easy. + +A nice explanation of the Lagrange method can be found here . + ## License Copyright (C) 2023 Stefan Müller