diff --git a/2022/day01/Cargo.lock b/2022/Cargo.lock similarity index 100% rename from 2022/day01/Cargo.lock rename to 2022/Cargo.lock diff --git a/2022/day01/Cargo.toml b/2022/Cargo.toml similarity index 100% rename from 2022/day01/Cargo.toml rename to 2022/Cargo.toml diff --git a/2022/day01/input.txt b/2022/input/day01.txt similarity index 100% rename from 2022/day01/input.txt rename to 2022/input/day01.txt diff --git a/2022/day02/input.txt b/2022/input/day02.txt similarity index 100% rename from 2022/day02/input.txt rename to 2022/input/day02.txt diff --git a/2022/day01/src/main.rs b/2022/src/day01.rs similarity index 92% rename from 2022/day01/src/main.rs rename to 2022/src/day01.rs index d6b2d2a..6f60736 100644 --- a/2022/day01/src/main.rs +++ b/2022/src/day01.rs @@ -30,13 +30,13 @@ fn update_max(max: &mut SortedVec, current: i32, step: i32) { } } -fn main() -> Result<(), io::Error> { +pub fn execute() -> Result<(), io::Error> { let step = get_step(); let mut max: SortedVec = SortedVec::new(); let mut current = 0; - for line in read_lines("input.txt")? { + for line in read_lines("input/day01.txt")? { let text = line?; current = match text.parse::() { Ok(value) => current + value, diff --git a/2022/day02/src/main.rs b/2022/src/day02.rs similarity index 93% rename from 2022/day02/src/main.rs rename to 2022/src/day02.rs index b1204f2..af83fe4 100644 --- a/2022/day02/src/main.rs +++ b/2022/src/day02.rs @@ -11,11 +11,11 @@ fn print_step(step: i8, value: u64) { println!("Step {} solution: {}", step, value); } -fn main() -> Result<(), io::Error> { +pub fn execute() -> Result<(), io::Error> { let mut score1: u64 = 0; let mut score2: u64 = 0; - for line in read_lines("input.txt")? { + for line in read_lines("input/day02.txt")? { let text = line?; let opp = parse_move(text.chars().nth(0).unwrap()); diff --git a/2022/src/main.rs b/2022/src/main.rs new file mode 100644 index 0000000..e334979 --- /dev/null +++ b/2022/src/main.rs @@ -0,0 +1,73 @@ +use std::env; +use std::io; + +const LATEST: u8 = 2; + +mod day01; +mod day02; +// mod day03; +// mod day04; +// mod day05; +// mod day06; +// mod day07; +// mod day08; +// mod day09; +// mod day10; +// mod day11; +// mod day12; +// mod day13; +// mod day14; +// mod day15; +// mod day16; +// mod day17; +// mod day18; +// mod day19; +// mod day20; +// mod day21; +// mod day22; +// mod day23; +// mod day24; +// mod day25; + +fn main() -> io::Result<()> { + let day = determine_day(LATEST); + match day { + 1 => day01::execute(), + 2 => day02::execute(), + // 3 => day03::execute(), + // 4 => day04::execute(), + // 5 => day05::execute(), + // 6 => day06::execute(), + // 7 => day07::execute(), + // 8 => day08::execute(), + // 9 => day09::execute(), + // 10 => day10::execute(), + // 11 => day11::execute(), + // 12 => day12::execute(), + // 13 => day13::execute(), + // 14 => day14::execute(), + // 15 => day15::execute(), + // 16 => day16::execute(), + // 17 => day17::execute(), + // 18 => day18::execute(), + // 19 => day19::execute(), + // 20 => day20::execute(), + // 21 => day21::execute(), + // 22 => day22::execute(), + // 23 => day23::execute(), + // 24 => day24::execute(), + // 25 => day25::execute(), + _ => panic!("Couldn't execute day {day}") + } +} + +fn determine_day(latest: u8) -> u8 { + let mut day = latest; + for arg in env::args() { + if let Ok(x) = arg.parse::() { + day = x; + break; + } + } + return day; +}