AdventOfCode2024/README.md

60 lines
4.0 KiB
Markdown
Raw Permalink Normal View History

2024-11-29 19:28:32 +01:00
# AdventOfCode2024
2024-12-02 11:08:38 +01:00
Solver for Advent of Code 2024 puzzles. <https://adventofcode.com/2024/>
2024-12-06 20:18:38 +01:00
This is a single command line application for the puzzles written in [C++23](https://en.cppreference.com/w/cpp/23) with CMake.
2024-12-02 11:08:38 +01:00
## Puzzle Input
This project does not contain the puzzle or example inputs as per the [copyright notice of Advent of Code](https://adventofcode.com/about). In order to run the compiled application, the puzzle inputs have to be downloaded from the [Advent of Code 2024](https://adventofcode.com/2024/) puzzle pages, and placed as text files into the `AdventOfCode2024\data` directory, e.g. `AdventOfCode2024\data\historian_hysteria.txt`, or `AdventOfCode2024\data\example\historian_hysteria.txt` for the unit tests. The application will output an error message with details if it cannot find an input file.
## Tests
The solution contains a unit test project to help troubleshoot issues and prevent regressions in the solver class framework. These tests cover the solutions for provided examples and full data inputs. I did not find a definitive source for it, but the full data inputs seem to be user-specific, so adding my solutions as tests does not spoil the solutions.
## Solutions
### Day 1: Historian Hysteria
:mag_right: Puzzle: <https://adventofcode.com/2024/day/1>, :white_check_mark: Solver: [`HistorianHysteria.cpp`](AdventOfCode2024/HistorianHysteria.cpp)
I'm using a `std::multiset` to collect and sort the values for both lists. This allows to use a single iteration of the left list and two iterations of the right list simultaneously to solve both parts. Nice application of iterators.
2024-11-29 19:36:35 +01:00
### Day 2: Red-Nosed Reports
2024-12-04 18:09:20 +01:00
:mag_right: Puzzle: <https://adventofcode.com/2024/day/2>, :white_check_mark: Solver: [`RedNosedReports.cpp`](AdventOfCode2024/RedNosedReports.cpp)
Here, we have a few conditionals to determine on the fly which of the numbers would make the report safe if dropped. The amount of cases is actually quite manageable.
2024-12-04 18:09:20 +01:00
### Day 3: Mull It Over
2024-12-04 18:09:20 +01:00
:mag_right: Puzzle: <https://adventofcode.com/2024/day/3>, :white_check_mark: Solver: [`MullItOver.cpp`](AdventOfCode2024/MullItOver.cpp)
2024-12-04 18:09:20 +01:00
A simple [finite state machine](AdventOfCode2024/StringStateMachine.h) crawling along the input character by character solves both parts nicely. The algorithm tracks whether `mul` instructions are enabled or not, but ignores this setting for part 1.
### Day 4: Ceres Search
:mag_right: Puzzle: <https://adventofcode.com/2024/day/4>, :white_check_mark: Solver: [`CeresSearch.cpp`](AdventOfCode2024/CeresSearch.cpp)
For this puzzle I added a class for [points in two-dimensional space](AdventOfCode2024/Point2.h), so I can use these for simplifying directional computations. With that, the algorithm looks for all `X` and `A` for part 1 and 2, respectively, and tries to find the remaining characters, starting from that `X` or `A`.
### Day 5: Print Queue
:mag_right: Puzzle: <https://adventofcode.com/2024/day/5>, :white_check_mark: Solver: [`PrintQueue.cpp`](AdventOfCode2024/PrintQueue.cpp)
My implementation uses an ordering matrix (a two-dimensional boolean array) to track which page combinations are ordered, and then queries that matrix for each ordered combination of pages in a single line. The same matrix can then also be used for a custom sort function for part 2.
2024-12-06 20:18:38 +01:00
## Thanks
* [Alexander Brouwer](https://github.com/Bromvlieg) for getting the project set up with CMake.
2024-11-29 19:36:35 +01:00
## License
Copyright (C) 2024 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/>.