#advent #example #aoc

bin+lib mbryant-aoc2021

Commented solutions to AoC 2021

2 releases

0.25.1 Feb 4, 2022
0.25.0 Feb 4, 2022

#320 in Profiling

MIT license

155KB
2.5K SLoC

AoC 2021

This contains efficient solutions for all Advent of Code 2021 puzzles. See AOC 2021 for more information.

View the docs for a walkthrough of the solutions.


lib.rs:

This crate contains reasonably efficient solutions for all Advent of Code 2021 puzzles. See AOC 2021 for more information, including puzzle prompts.

If you haven't used Rust before, these are generated docs from the codebase. They should cover my thoughts on the problem and solutions, provide an overview, and allow easily browsing through the code via the [src] buttons on the right side of the screen. This is the first time I've thought of displaying more than code via Rust docs like this, so I'm curious for feedback.

Initial Goal

Execute all puzzles before the JVM can start up (~800ms).

Note: This was solidly achieved, as all puzzles run in <100ms on each benchmarked system. On my desktop, they run faster than python can cold-start (measured via time python3 -c "exit()")!

Code layout

Each day's code is in a different module (linked at the bottom of this page), with three mandatory functions: generator, part1, and part2. generator is passed the input text, parses and computes a useful intermediate representation from it, and a reference to that value is passed to part1 and part2.

This allows us to focus on each part individually, as well as track the cost of parsing the input. However, it means we often end up doing duplicated work between part1 and part2.

Solutions are intended to be general, but may require constants to be changed. For example, if the input is a fixed-size grid, data structures will likely use a constant set to that fixed size, since this enables storing data with less required pointer traversing.

Due to the anemic (by modern standards) cache on my desktop machine, I frequently optimize for memory efficiency rather than amount of work done by the CPU. This may not pay off as well on a system with a faster memory hierarchy.

Benchmarking

Solutions have been benchmarked on a few different systems, but the main development was done on an Intel i7-6700K. System information and results can be found under the benchmarks module.

For the full code, including framework and benchmarking code, see the Gitlab repo.

Dependencies

~2–12MB
~91K SLoC