1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
mod day_1;
mod day_2;
mod day_3;
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),
2 => day_2::run(input),
3 => day_3::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);
}
|