AoC2021/src/main.rs

73 lines
2.1 KiB
Rust
Raw Normal View History

2021-12-01 17:07:17 +01:00
use std::fs::read_to_string;
use chrono::Datelike;
2021-12-01 20:53:49 +01:00
use clap::{App, Arg};
use crate::day01::Day01;
2021-12-02 08:50:56 +01:00
use crate::day02::Day02;
2021-12-03 10:02:46 +01:00
use crate::day03::Day03;
2021-12-04 09:52:49 +01:00
use crate::day04::Day04;
2021-12-01 17:07:17 +01:00
use crate::day::Day;
mod day;
2021-12-01 20:53:49 +01:00
mod day01;
2021-12-02 08:50:56 +01:00
mod day02;
2021-12-03 10:02:46 +01:00
mod day03;
2021-12-04 09:52:49 +01:00
mod day04;
2021-12-01 17:07:17 +01:00
fn load_input(day: &str) -> String {
read_to_string(format!("./input/day{}", day)).expect("Could not load input")
}
2021-12-03 10:02:46 +01:00
fn run_day(days: &[Box<dyn Day>], day: usize) {
2021-12-01 17:07:17 +01:00
if let Some(d) = days.get(day - 1) {
2021-12-03 10:02:46 +01:00
let day_code = d;
2021-12-01 17:07:17 +01:00
println!("Running day {}!", day);
println!("\tPart 1: {}", d.part1());
println!("\tPart 2: {}", day_code.part2());
} else {
eprintln!("Day {} is not available!", day);
}
}
fn main() {
let matches = App::new("AOC Time!")
.version("1.0")
.author("J00LZ")
.about("How to overengineer AOC in a single program...")
.arg(Arg::with_name("v")
.short("v")
.multiple(true)
.help("Sets the level of verbosity"))
.arg(Arg::with_name("all")
.short("a")
.long("all")
.help("run all available days"))
.arg(Arg::with_name("DAY")
.takes_value(true)
.multiple(true))
.get_matches();
2021-12-03 10:02:46 +01:00
let days: Vec<Box<dyn Day>> = vec![Box::new(Day01::init(load_input("01"))), Box::new(Day02::init(load_input("02"))),
2021-12-04 09:52:49 +01:00
Box::new(Day03::init(load_input("03"))),
Box::new(Day04::init(load_input("04")))];
2021-12-01 17:07:17 +01:00
2021-12-01 20:53:49 +01:00
let _verbosity = matches.occurrences_of("v");
2021-12-01 17:07:17 +01:00
if matches.is_present("all") {
let l = days.len();
println!("running {} days!", l);
2021-12-03 10:02:46 +01:00
for v in 1..=l {
2021-12-01 17:07:17 +01:00
run_day(&days, v);
}
} else if let Some(d) = matches.values_of("DAY") {
2021-12-03 10:02:46 +01:00
let d = d.map(|x| x.parse::<usize>().expect("Did not provide an int!"));
2021-12-01 17:07:17 +01:00
for v in d {
2021-12-03 10:02:46 +01:00
run_day(&days, v);
2021-12-01 17:07:17 +01:00
}
} else {
let v = chrono::Local::now();
if v.month() != 12 {
2021-12-03 10:02:46 +01:00
println!("This was really only meant to be used in december...");
}
2021-12-03 10:02:46 +01:00
run_day(&days, v.day() as usize);
2021-12-01 17:07:17 +01:00
}
}