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
316 downloads per month
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