diff options
| author | Arne Dußin | 2021-12-01 13:05:54 +0100 |
|---|---|---|
| committer | Arne Dußin | 2021-12-01 13:05:54 +0100 |
| commit | 36dc513e41c349fa69231b81433ccbad911743a6 (patch) | |
| tree | 791221a43654e77bf6c49a8231dc0e814539dc05 /src/main.rs | |
| download | aoc2021-36dc513e41c349fa69231b81433ccbad911743a6.tar.gz aoc2021-36dc513e41c349fa69231b81433ccbad911743a6.zip | |
Add solution to day 1
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c45571e --- /dev/null +++ b/src/main.rs @@ -0,0 +1,52 @@ +mod day_1; + +use std::fs::File; +use std::io::{BufRead, BufReader}; +use std::path::PathBuf; +use std::str::FromStr; + +use argparse::{ArgumentParser, Store}; + +fn read_input(day: u8) -> Vec<String> +{ + let file_name = PathBuf::from_str("input") + .unwrap() + .join(format!("day_{}.txt", day)); + let input_file = + File::open(&file_name).expect(&format!("Unable to open input file {:?}", file_name)); + let reader = BufReader::new(input_file); + + reader + .lines() + .map(|r| r.expect("Unable to read line in input file")) + .collect() +} + +fn run(day: u8, input: Vec<String>) +{ + match day { + 1 => day_1::run(input), + o => panic!("Day {} is not implemented (yet)", o), + } +} + +fn main() +{ + let mut day: u8 = 1; + { + let mut ap = ArgumentParser::new(); + ap.set_description("Run advent of code 2015 solvers"); + + ap.refer(&mut day).add_option( + &["-d", "--day"], + Store, + "The day of the month of which the solver should be run", + ); + + ap.parse_args_or_exit(); + } + + println!("Attempting to solve day {}", day); + let input = read_input(day); + run(day, input); +} |
