Skip to content

Instantly share code, notes, and snippets.

@ritobanrc
Created November 17, 2020 17:30
Show Gist options
  • Save ritobanrc/6100544aca8dd0e61374328640d408b5 to your computer and use it in GitHub Desktop.
Save ritobanrc/6100544aca8dd0e61374328640d408b5 to your computer and use it in GitHub Desktop.
A short script to easily handle the functions for advent of code.
/// The `main` function for each day is in `dayXX.rs`, called `dayXX_main()`. To
/// run all the solutions, simply run `cargo test`. Inputs should be placed in a folder
/// input/dayXX.txt. This also requires the `paste = "0.1.0"` and `anyhow = "1.0.0"` crates
/// for creating the function names and handing errors, respectively.
use std::io;
pub fn load_input(day: usize) -> io::Result<String> {
use std::fs::read_to_string;
use std::path::PathBuf;
let path: PathBuf = ["input", &format!("day{:02}.txt", day)].iter().collect();
read_to_string(path)
}
#[macro_export]
macro_rules! aoc {
($day: expr) => {
paste::item! {
#[test]
fn [<day $day _test>]() -> anyhow::Result<()> {
[<day $day _main>]()
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment