AdventOfCode2023/README.md

36 lines
2.4 KiB
Markdown
Raw Normal View History

2023-12-02 00:26:56 +01:00
# Advent of Code 2023
2023-12-01 23:03:05 +01:00
2023-12-03 01:55:36 +01:00
Solver for [Advent of Code 2023](https://adventofcode.com/2023/) puzzles.
2023-12-01 23:04:26 +01:00
## 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>.
2023-12-01 23:04:26 +01:00
## License
Copyright (C) 2023 Stefan Müller
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.