Added commentary for a some of the solved puzzles

This commit is contained in:
Stefan Müller 2023-12-09 23:53:06 +01:00 committed by Stefan Müller
parent 09baefc881
commit 7461ab7536
1 changed files with 22 additions and 0 deletions

View File

@ -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 <http://bueler.github.io/M310F11/polybasics.pdf>.
## License
Copyright (C) 2023 Stefan Müller