elvish
Overengineered Advent of Code framework for Rust - not quite Santa's elves.
elvish is a framework for writing your Advent of Code solutions with the least amount of boilerplate as possible.
Features
- Declare solutions with simple macro
- Fetching and caching of user input
- Run solutions as binary
- Automatically copy solutions to clipboard
- Simple and consice syntax to write out 90% of required tests
- See the puzzle description as docs on the annotated function
- Conditional compilation to compile a single day
Quick example
This is my solution for day 1 of 2023 using elvish:
;
example!;
Usage
Note: The examples directory has a full implementation of the 2023 advent of code using elvish, for reference.
Installing
Clone the template repo:
If you want to use a remote, change the url:
Then, edit the .env.example by setting your session token and the year, and make it the primary .env file.
To use elvish, first add it as a dependency
Then, declare a Solutions struct in the root of the crate:
// in main.rs
;
And add a main function:
// in main.rs
;
run_fn!;
For the data fetching to work you need to add your session token and year in a .env file (make sure to .gitignore it).
SESSION_TOKEN=something
YEAR=202X
Finally, you need to add some cargo features to conditionally compile each day:
[]
# You can add your own features here
# Detected by `elvish`
= []
= []
= []
= []
= ["part1", "part2"]
= ["part1"]
= ["part2"]
= ["both"]
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= []
= ["day01"]
= ["day02"]
= ["day03"]
= ["day04"]
= ["day05"]
= ["day06"]
= ["day07"]
= ["day08"]
= ["day09"]
= ["day10"]
= ["day11"]
= ["day12"]
= ["day13"]
= ["day14"]
= ["day15"]
= ["day16"]
= ["day17"]
= ["day18"]
= ["day19"]
= ["day20"]
= ["day21"]
= ["day22"]
= ["day23"]
= ["day24"]
= ["day25"]
= [
"day01",
"day02",
"day03",
"day04",
"day05",
"day06",
"day07",
"day08",
"day09",
"day10",
"day11",
"day12",
"day13",
"day14",
"day15",
"day16",
"day17",
"day18",
"day19",
"day20",
"day21",
"day22",
"day23",
"day24",
"day25",
]
Running
By default it compiles a binary that includes all days and runs it. To specify a day, you can use feature flags:
or, to run both parts,
and, as a shorthand
Test examples from prompts
elvish provides convinient macros to declare example inputs for 90% of cases:
- One example per part
example!;
- Same example for both parts
example!;
- More than one example for a part
example!;
Other
Future roadmap
- Warn when day shouldn't be available yet