qol
This commit is contained in:
parent
19fe0a53ff
commit
2c9790a690
7 changed files with 48 additions and 26 deletions
|
|
@ -5,7 +5,8 @@ pub fn load_actual(year: usize, day: usize) -> io::Result<String> {
|
|||
fs::read_to_string(path)
|
||||
}
|
||||
|
||||
pub fn load_test(year: usize, day: usize) -> io::Result<String> {
|
||||
let path = format!("./examples/{year}/day{:02}", day);
|
||||
fs::read_to_string(path)
|
||||
pub fn load_test(year: usize, day: usize) -> (io::Result<String>, io::Result<String>) {
|
||||
let input_path = format!("./examples/{year}/day{:02}", day);
|
||||
let result_path = format!("./examples/{year}/day{:02}_solution", day);
|
||||
(fs::read_to_string(input_path), fs::read_to_string(result_path))
|
||||
}
|
||||
|
|
|
|||
46
src/main.rs
46
src/main.rs
|
|
@ -24,23 +24,31 @@ fn main() {
|
|||
fetch_input(year, day).expect("Set ADVENT_TOKEN to the correct session cookie to fetch input automatically");
|
||||
}
|
||||
|
||||
println!("Attempting to run {year}/{day}");
|
||||
|
||||
let Ok(data) = load_actual(year, day)
|
||||
else { panic!("No Input Data"); };
|
||||
|
||||
let now = Instant::now();
|
||||
|
||||
let part1 = solution(&data, year, day, 1).unwrap();
|
||||
|
||||
let elapsed1 = now.elapsed();
|
||||
|
||||
let now = Instant::now();
|
||||
|
||||
let part2 = solution(&data, year, day, 2).unwrap();
|
||||
|
||||
let elapsed2 = now.elapsed();
|
||||
|
||||
println!("Part 1 result is {}, took {}ms", part1, elapsed1.as_millis());
|
||||
println!("Part 2 result is {}, took {}ms", part2, elapsed2.as_millis());
|
||||
run_all();
|
||||
}
|
||||
|
||||
fn run_all() {
|
||||
let years_to_run = [2023, 2024];
|
||||
|
||||
if env::var("ADVENT_TOKEN").is_ok() {
|
||||
for year in years_to_run {
|
||||
for day in 1..=25 {
|
||||
println!("Pre-fetching input for {year}/{:02}", day);
|
||||
fetch_input(year, day).expect("Set ADVENT_TOKEN to the correct session cookie to fetch input automatically");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for year in years_to_run {
|
||||
for day in 1..=25 {
|
||||
for part in [1, 2] {
|
||||
let input = load_actual(year, day).unwrap_or_else(|_| panic!("Missing input for {}/{:02}", year, day));
|
||||
|
||||
let now = Instant::now();
|
||||
let result = solution(&input, year, day, part).unwrap_or_else(|| panic!("No solution at {}/{:02}", year, day));
|
||||
let time_passed = now.elapsed().as_millis();
|
||||
println!("Running Year {}, Day {:02}, Part {} - Result {} - took {}ms", year, day, part, result, time_passed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use shared::Answer;
|
|||
|
||||
pub fn solution(input: &str, year: usize, day: usize, part: usize) -> Option<Answer> {
|
||||
match year {
|
||||
2023 => aoc2024::solution(input, day, part),
|
||||
2023 => aoc2023::solution(input, day, part),
|
||||
2024 => aoc2024::solution(input, day, part),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue