#advent #day #challenge #input #runner #tool #cargo

build aocr

A simple task runner and support tool for Advent of Code challenges

3 releases

new 0.2.2 Nov 18, 2024
0.2.1 Nov 18, 2024
0.2.0 Nov 18, 2024

#65 in Build Utils

Download history 316/week @ 2024-11-13

316 downloads per month

MIT license

47KB
892 lines

Advent of Code Runner πŸ¦€ Rust Edition

Thank you for being interested in my Advent of Code development tool! I built this ahead of Advent of Code 2024 to be a nice helper tool for keeping each day organized and separated. I hope you find it useful!

Prerequisites

rustup installed with cargo and rustc and toolchain for your platform installed.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup update

πŸš€ Getting Started

$ cargo install aocr
$ aocr init aoc24 
$ cd aoc24
$ aocr watch

⭐ Quick overview of Advent of Code

Advent of Code or AoC is a 25 day programming challenge with a new problem coming out each day. Each problem has two parts, part 1 and part 2.

Generally each part takes a small text file as input and computes a number as output. You input the number into Advent of Code in order to verify your solution as correct or incorrect. Each day you must pass part 1 before being shown the problem for part 2.

πŸ“– Day to Day Usage

Each day has its own library crate located at day## comprised of 2 files:

  • Cargo.toml
  • src/lib.rs

Each day's library crate contains two functions called part1 and part2 that takes as input a &str string slice and return a usize unsized integer. Implement your solution for parts 1 and 2 in these functions.

/// day01/src/lib.rs
pub fn part1(input: &str) -> usize {
    // TODO: Implement part 1 solution
    0
}

pub fn part2(input: &str) -> usize {
    // TODO: Implement part 2 solution
    0
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_part1() {
        let input = "";
        assert_eq!(part1(input), 1);
    }

    #[test]
    fn test_part2() {
        let input = "";
        assert_eq!(part2(input), 0);
    }
}

Initialize your working folder

Use aocr to initialize a folder:

aocr init <folder>

This folder will be populated with a cargo workspace as well as a fresh git repository. You need to be in this workspace when executing aocr commands for them to register correctly.

How to run aocr

To start the interactive terminal user interface (tui), from within your initialized workspace:

aocr watch

To view help:

# Show help
aocr --help

To run a day and selected part without the terminal user interface:

# Run a day and selected parts
aocr <day> <part>

Navigating the TUI and providing input data

When aocr watch runs, you can use the direction arrows or h/j/k/l keys (vim-bindings) to move the day/part selector left/up/down/right.

Press the i key to set the input for the selected day.

β”ŒDaysβ”€β”€β”€β”β”ŒInput (Ctrl+S or Ctrl+Enter to save, Ctrl+V ┐
β”‚01 1 2 β”‚β”‚// input goes here_                         β”‚
β”‚02 1 2 β”‚β”‚                                            β”‚
β”‚03 1 2 β”‚β”‚                                            β”‚
β”‚04 1 2 β”‚β”‚                                            β”‚
β”‚05 1 2 β”‚β”‚                                            β”‚
β”‚06 1 2 β”‚β”‚                                            β”‚
β”‚07 1 2 β”‚β”‚                                            β”‚
β”‚08 1 2 β”‚β”‚                                            β”‚
β”‚09 1 2 β”‚β”‚                                            β”‚
β”‚10 1 2 β”‚β”‚                                            β”‚
β”‚11 1 2 β”‚β”‚                                            β”‚
β”‚12 1 2 β”‚β”‚                                            β”‚
β”‚13 1 2 β”‚β”‚                                            β”‚
β”‚14 1 2 β”‚β”‚                                            β”‚
β”‚15 1 2 β”‚β”‚                                            β”‚
β”‚16 1 2 β”‚β”‚                                            β”‚
β”‚17 1 2 β”‚β”‚                                            β”‚
β”‚18 1 2 β”‚β”‚                                            β”‚
β”‚19 1 2 β”‚β”‚                                            β”‚
β”‚20 1 2 β”‚β”‚                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Press enter or w (watch) on a selected day to start running cargo check on the library crate for the selected day:

β”ŒDaysβ”€β”€β”€β”β”ŒCargo output day 1 part 1───────────────────┐
β”‚01 1 2 β”‚β”‚Checking day 1 part 1...                    β”‚
β”‚02 1 2 β”‚β”‚warning: unused variable: `input`           β”‚
β”‚03 1 2 β”‚β”‚ --> day01/src/lib.rs:3:14                  β”‚
β”‚04 1 2 β”‚β”‚  |                                         β”‚
β”‚05 1 2 β”‚β”‚3 | pub fn part1(input: &str) -> usize {    β”‚
β”‚06 1 2 β”‚β”‚  |              ^^^^^ help: if this is inteβ”‚
β”‚07 1 2 β”‚β”‚  |                                         β”‚
β”‚08 1 2 β”‚β”‚  = note: `#[warn(unused_variables)]` on by β”‚
β”‚09 1 2 β”‚β”‚                                            β”‚
β”‚10 1 2 β”‚β”‚warning: unused variable: `input`           β”‚
β”‚11 1 2 β”‚β”‚ --> day01/src/lib.rs:8:14                  β”‚
β”‚12 1 2 β”‚β”‚  |                                         β”‚
β”‚13 1 2 β”‚β”‚8 | pub fn part2(input: &str) -> usize {    β”‚
β”‚14 1 2 β”‚β”‚  |              ^^^^^ help: if this is inteβ”‚
β”‚15 1 2 β”‚β”‚                                            β”‚
β”‚16 1 2 β”‚β”‚warning: `day01` (lib) generated 2 warnings β”‚
β”‚17 1 2 β”‚β”‚    Finished `dev` profile [unoptimized + deβ”‚
β”‚18 1 2 β”‚β”‚                                            β”‚
β”‚19 1 2 β”‚β”‚                                            β”‚
β”‚20 1 2 β”‚β”‚                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Press t on a selected day to run cargo test on the library crate for the selected day:

β”ŒDaysβ”€β”€β”€β”β”ŒCargo output day 1 part 1───────────────────┐
β”‚01 1 2 β”‚β”‚warning: unused variable: `input`           β”‚
β”‚02 1 2 β”‚β”‚ --> day01/src/lib.rs:3:14                  β”‚
β”‚03 1 2 β”‚β”‚  |                                         β”‚
β”‚04 1 2 β”‚β”‚3 | pub fn part1(input: &str) -> usize {    β”‚
β”‚05 1 2 β”‚β”‚  |              ^^^^^ help: if this is inteβ”‚
β”‚06 1 2 β”‚β”‚  |                                         β”‚
β”‚07 1 2 β”‚β”‚  = note: `#[warn(unused_variables)]` on by β”‚
β”‚08 1 2 β”‚β”‚                                            β”‚
β”‚09 1 2 β”‚β”‚warning: unused variable: `input`           β”‚
β”‚10 1 2 β”‚β”‚ --> day01/src/lib.rs:8:14                  β”‚
β”‚11 1 2 β”‚β”‚  |                                         β”‚
β”‚12 1 2 β”‚β”‚8 | pub fn part2(input: &str) -> usize {    β”‚
β”‚13 1 2 β”‚β”‚  |              ^^^^^ help: if this is inteβ”‚
β”‚14 1 2 β”‚β”‚                                            β”‚
β”‚15 1 2 β”‚β”‚warning: `day01` (lib) generated 2 warnings β”‚
β”‚16 1 2 β”‚β”‚warning: `day01` (lib test) generated 2 warnβ”‚
β”‚17 1 2 β”‚β”‚    Finished `test` profile [unoptimized + dβ”‚
β”‚18 1 2 β”‚β”‚     Running unittests src/lib.rs (target/deβ”‚
β”‚19 1 2 β”‚β”‚error: test failed, to rerun pass `-p day01 β”‚
β”‚20 1 2 β”‚β”‚                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Press r on the selected day to run the selected part function and generate a result:

β”ŒDaysβ”€β”€β”€β”β”ŒCargo output day 1 part 1───────────────────┐
β”‚01 1 2 β”‚β”‚Result: 0                                   β”‚
β”‚02 1 2 β”‚β”‚                                            β”‚
β”‚03 1 2 β”‚β”‚                                            β”‚
β”‚04 1 2 β”‚β”‚                                            β”‚
β”‚05 1 2 β”‚β”‚                                            β”‚
β”‚06 1 2 β”‚β”‚                                            β”‚
β”‚07 1 2 β”‚β”‚                                            β”‚
β”‚08 1 2 β”‚β”‚                                            β”‚
β”‚09 1 2 β”‚β”‚                                            β”‚
β”‚10 1 2 β”‚β”‚                                            β”‚
β”‚11 1 2 β”‚β”‚                                            β”‚
β”‚12 1 2 β”‚β”‚                                            β”‚
β”‚13 1 2 β”‚β”‚                                            β”‚
β”‚14 1 2 β”‚β”‚                                            β”‚
β”‚15 1 2 β”‚β”‚                                            β”‚
β”‚16 1 2 β”‚β”‚                                            β”‚
β”‚17 1 2 β”‚β”‚                                            β”‚
β”‚18 1 2 β”‚β”‚                                            β”‚
β”‚19 1 2 β”‚β”‚                                            β”‚
β”‚20 1 2 β”‚β”‚                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

If you need to modify the input file for any reason, they are stored at inputs/day##_part#.txt in your repository. Feel free to edit/delete this file. If you delete it, the next time you attempt to run that day & part, aocr will prompt you for input again.

The input text will be made available to you via the AoC website.

Dependencies

~11–22MB
~346K SLoC