Skip to content

My Rust solutions for Advent Of Code 2022

Notifications You must be signed in to change notification settings

Lugrim/AdventOfCode-2022

 
 

Repository files navigation

Advent of Code 2022

My solutions for the Advent Of Code 2022 puzzles written in Rust.

Can be found both on GitHub and my Gitea.

This code in organized with :

  • A top-level crate to run tests and benchmarks
  • Sub-level crates for each day (dayXX)
  • A common crate for the common methods

Summary :

Stars obtained :

⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛

Run times (on a Dell Precision 3571 with an i7-12700H) :

Day 01 Day 02 Day 03 Day 04 Day 05
Part 1 27.3 µs 18.8 µs 28.6 µs 45.4 µs 35.8 µs
Part 2 30.6 µs 29.0 µs 26.6 µs 45.9 µs 35.6 µs
Day 06 Day 07 Day 08 Day 09 Day 10
Part 1
Part 2
Day 11 Day 12 Day 13 Day 14 Day 15
Part 1
Part 2
Day 16 Day 17 Day 18 Day 19 Day 20
Part 1
Part 2
Day 21 Day 22 Day 23 Day 24 Day 25
Part 1
Part 2

In order to check those benchmarks, run cargo bench on the root crate.

Sub-level day crates

The sublevel day crates are both executable and libraries. The main logic is always implemented in lib.rs but a main method exists in main.rs to read the data file and show the answers. So, you can go to any day and run cargo run to see the day's answers.

dayXX
|- Cargo.toml
`- src/
   |- main.rs
   `- lib.rs

Tests

Every sub-level day crate contains tests for the examples given on that day. You can run cargo test in those day crates to see that examples are successfully processed.

The common crate

The common crate defines methods and macros used by multiple day crates :

  • read_data : reads the data from the file into a String
  • tests! : a macro designed to write quick unit tests based on an input and the expected output

Top-level tests and benchmarks

The metrics provided above are computed using cargo bench in the top-level crate. That crate also contains tests to check that the results of the computation are still valid for all days and parts.

License

This entire code is licensed under ACSL, with the criterion crates licensed under MIT.

About

My Rust solutions for Advent Of Code 2022

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%