Daily bit(e) of C++ | Advent of Code: Day 15
Daily bit(e) of C++ #348, Advent of Code using Modern C++: Day 15.
Welcome to day 15 of Advent of Code using Modern C++. Before you start reading, I highly encourage you to try to solve the two problems yourself: https://adventofcode.com/2023/day/15.
If you missed it, I have prepared a template repository for C++, with a development environment (through a devcontainer) with a bleeding edge version of the C++ toolchain: https://github.com/HappyCerberus/aoc-2023-cpp.
Today, we are following the HASHMAP procedure to organize focusing lenses.
Part one
For part one, we need to implement a hash function, which we can then use to fold over all instructions.
Part two
In part two, we are implementing a simple hashmap. The problem formulation spells out the design, so we only have to translate this into C++.
This leaves us with the parsing code. We can easily iterate over all instructions; however, parsing out the type of instruction requires a bit more work.
Conclusion
How did you do with today’s problems?
Share your solutions and insights. Check out the repository with solutions and links to all articles: https://github.com/HappyCerberus/aoc-2023-cpp-solutions.