Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 3.14 KB

README.md

File metadata and controls

42 lines (34 loc) · 3.14 KB

Advent of Code 2018

This repository contains my solutions for the Advent of Code 2018 programming puzzles, written in Rust 🦀.

This was my second Advent of Code, done a year or two after the event debuted.

I used this as an opportunity to practice my Rust language skills and to begin exercising language features I hadn't used before. My goals were:

  1. Solve the puzzles in a reasonably robust way.
    • Create solutions that were "general enough", such that any reasonable input would be solved by the program. In some cases it would be prohibitively difficult to make a truly general solution and the input data showed clear intent to not require one, then some shortcuts were acceptable.
    • Create programs with good structure. Use structs, mods, and composition.
    • Follow best practices by writing unit tests wherever it benefited the process of solving the puzzle. Typically, any important functionality with non-trivial edge cases would be tested.
    • Documentation was not a priority. I made no effort to add comments describing the overall solution, nor the individual functions. Comments were added only where it helped the writing process. In a real life production environment comments and good documentation would of course be required.
  2. Write idiomatic Rust code wherever possible.
    • The code compiles with no warnings, has no clippy warnings (see below), and conforms to the Rust formatting guidelines.
    • Use only features of the latest version of stable Rust.
    • No unsafe code.
  3. Learn or practice features of the Rust language where the solutions present an opportunity, even if it's not the ideal fit for the situation.
  4. Create efficient solutions. I usually chose good structure over optimization, but for days when the solution took a long time to run the optimization became a priority. At this point many solutions are nowhere near optimal and significant optimization could be done.
  5. Use few external crates, relying mainly on the standard library.

Building and running

This project uses the Cargo AoC framework, which must be installed in order to build the program. Cargo AoC makes it easy to download input files and supply them to the program, separate generators and solvers, and execute solutions selectively. It also provides an easy way to benchmark solutions.

All solutions can be tested and run with the usual cargo commands:

  • cargo test
  • cargo run --release

The solutions can be selectively run as follows:

  • cargo aoc -d D, where D is replaced with the relevant day number (1-25)
  • cargo aoc -d D -p P, same as above but replacing P with the relevant part number (1-2)

Clippy

The clippy linter does not produce any warnings on the code at the default warning levels, with few exceptions where it is suppressed:

  • clippy::bool_comparison and clippy::needless_bool - I find it far more readable to explicitly write booleans in most places they are used

Commit hook

Each commit is checked with the following commands:

  • cargo fmt -- --check
  • cargo test
  • cargo clean -p advent_of_code_2018; cargo clippy -- -Dwarnings

Execution times

TBD