#advent-of-code #puzzle #attempt #day #input #year #aoc

bin+lib aoc-rs-1npo

My attempt at using Rust to solve Advent of Code puzzles

7 releases (4 breaking)

new 0.5.1 Dec 3, 2024
0.5.0 Dec 3, 2024
0.4.1 Dec 2, 2024
0.3.0 Dec 2, 2024
0.1.0 Dec 2, 2024

#987 in Command line utilities

MIT license

18KB
349 lines

aoc-rs

This is my attempt at using Rust to build an Advent of Code puzzle solver. It's also my attempt to learn Rust!

Install

cargo install aoc-rs-1npo

Usage

aoc-rs <COMMAND> <YEAR> <DAY> <PART>

The first three arguments are required, PART defaults to 1 if absent.

There are 2 commands: solve and submit.

Use the solve command to print the solution to the screen.

For example:

aoc-rs solve 2024 1 1
[2024-12-03T01:29:14Z INFO  aoc_rs_1npo::web] Got puzzle input from cached file
[2024-12-03T01:29:14Z INFO  aoc_rs_1npo::puzzles] Got puzzle input for year 2024 day 1
[2024-12-03T01:29:14Z INFO  aoc_rs_1npo::puzzles] Solution for part 1 = "1651298"

Use the submit command to submit the solution as an answer to adventofcode.com.

For example:

aoc-rs submit 2024 1 2
[2024-12-03T01:35:46Z INFO  aoc_rs_1npo::web] Got puzzle input from cached file
[2024-12-03T01:35:46Z INFO  aoc_rs_1npo::puzzles] Got puzzle input for year 2024 day 1
[2024-12-03T01:35:46Z INFO  aoc_rs_1npo::puzzles] Solution for part 2 = "21306195"
[2024-12-03T01:35:46Z INFO  aoc_rs_1npo::puzzles] Puzzle solved! Great job!

Developer Guide

Adding Solutions for New Days

Replace DAY, PART, YYYY, and N with the appropriate values

  1. Create src/puzzles/yearYYYY/dayN.rs
  2. Add pub mod dayN; to src/puzzles/yearYYYY/mod.rs
  3. Add solutions.insert((2024, DAY, PART), Box::new(yearYYYY::dayN::partN)); to get_puzzle_solution() in src/puzzles/mod.rs
  4. Implement the input parsing for the day's puzzle in yearYYYY::dayN::parse()
  5. Implement the solutions for parts 1 and 2 in yearYYYY::dayN::part1() and yearYYYY::dayN::part2() respectively

Adding a New Year

  1. Create src/puzzles/yearYYYY
  2. Create src/puzzles/yearYYYY/mod.rs
  3. Follow the steps above to create dayN.rs files for the year

Acknowledgements

Thanks to Nir for his dayN.rs template and his file caching code :)

Dependencies

~9–39MB
~611K SLoC