My third Advent of Code. This time using C++, the objective is to have a total runtime of less than 60 seconds.
- Intel(R) Core(TM) i7-5600U: 13.9 sec
- Intel(R) Core(TM) i7-7820HQ: 13.5 sec
- Intel(R) Core(TM) i7-11850H: 7.7 sec
Meson and NixOS do not work well together: meson strips RPATH
Workaround: LDFLAGS="-Wl,-rpath=${fmtlog}/lib"
Deleting while iterating a hash map (or set) is not possible in Java, but in C++ it is:
it = co2_numbers.erase(it);
Hardest puzzles:
- Day 19: Beacon Scanner
- Day 21: Dirac Dice
- Day 22: Reactor Reboot
std::span
is very useful
- took me quite a while to come up with bins and avoid the out-of-memory problem (for me the hardest problem in days 1-11)
std::accumulate
: the last argument type determines the type used for the summation! use(uint64_t)0
to prevent integer overflow for large positive numbers.
std::tuple
is not hashable by default, see https://stackoverflow.com/a/15161034 for a solution
- Used the generic backtracking recipe from Skiena. DFS would have been more efficient though.
- Lots of bit fiddling, but quite fun
- Should get rid of
stringstream
, possible speed up
- Ugly solution using string instead of a tree representation, but still reasonably fast
- Lots of corner cases and bugs/off-by-one errors (=> many tests)
- Did not enjoy this puzzle
- Lanternfish revisited
- To toggle between 0 and 1 in the loop:
active_idx = 1 - active_idx
. This is the same asactive_idx = (active_idx + 1) % 2
. - Part 2 was tricky
- Many corner-cases to consider
- Quite difficult
- Rather easy using backtracking approach although much slower than A*
- Does not produce correct result when compiling with gcc! You must use clang. Weird.
- My favorite puzzle! Very interesting.
- Used a Python script to convert ALU to CPP code and then simplified the code until I found a solution => Does not work with other inputs than mine