-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
56 lines (45 loc) · 1.44 KB
/
main.rs
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
extern crate aoc_utils;
#[macro_use] extern crate lazy_static;
extern crate regex;
extern crate md5;
extern crate sha1;
mod part1;
mod part2;
use aoc_utils::prelude::*;
use regex::Regex;
use std::{collections::{HashMap, VecDeque}, env};
const DAY: u32 = 14;
type InputType = usize;
fn main() {
// READ input
let args: Vec<String> = env::args().collect();
// Parse command line arguments
let input_name = if args.len() > 1 {
&args[1]
} else {
"puzzle1"
};
let verbose = args.contains(&String::from("-v")) || args.contains(&String::from("--verbose"));
if verbose {
println!("Loading data from input file {}", input_name);
}
// READ & PARSE input
let (input, puzzle_config) = parse_input(input_name, verbose);
// SOLVE puzzles
let res1 = part1::solve(input, &puzzle_config);
let res2 = part2::solve(input, &puzzle_config);
println!("results: {} and {}", res1, res2);
}
fn parse_input(input_name: &str, verbose: bool) -> (InputType, PuzzleConfig) {
let config = ImportConfig::new(2018, DAY, "../../_inputs/day{day}/");
let (input, puzzle_config) = import_with_puzzle_config(&config, input_name).unwrap();
if verbose {
println!("raw input: {:?}", input);
}
let data = input[0].parse::<usize>().unwrap();
if verbose {
println!("input parsed: {:?}", data);
println!("config: {:?}", puzzle_config);
}
(data, puzzle_config)
}