Move code into a single cargo module with an execution harness.

This commit is contained in:
Anna Rose 2024-02-15 17:49:57 +00:00
parent 5b3a5d829d
commit 5bb3392691
7 changed files with 77 additions and 4 deletions

View File

@ -30,13 +30,13 @@ fn update_max(max: &mut SortedVec<i32>, current: i32, step: i32) {
} }
} }
fn main() -> Result<(), io::Error> { pub fn execute() -> Result<(), io::Error> {
let step = get_step(); let step = get_step();
let mut max: SortedVec<i32> = SortedVec::new(); let mut max: SortedVec<i32> = SortedVec::new();
let mut current = 0; let mut current = 0;
for line in read_lines("input.txt")? { for line in read_lines("input/day01.txt")? {
let text = line?; let text = line?;
current = match text.parse::<i32>() { current = match text.parse::<i32>() {
Ok(value) => current + value, Ok(value) => current + value,

View File

@ -11,11 +11,11 @@ fn print_step(step: i8, value: u64) {
println!("Step {} solution: {}", step, value); println!("Step {} solution: {}", step, value);
} }
fn main() -> Result<(), io::Error> { pub fn execute() -> Result<(), io::Error> {
let mut score1: u64 = 0; let mut score1: u64 = 0;
let mut score2: 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 text = line?;
let opp = parse_move(text.chars().nth(0).unwrap()); let opp = parse_move(text.chars().nth(0).unwrap());

73
2022/src/main.rs Normal file
View File

@ -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::<u8>() {
day = x;
break;
}
}
return day;
}