Advent of Code 2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

#![feature(is_sorted)]
#![feature(option_flattening)]
#[macro_use]
extern crate clap;
use clap::{Arg, App};
use std::fs::File;
use std::io::BufReader;
mod day1;
mod day2;
mod day3;
mod day4;
mod day5;
mod intcode;
fn main() {
let matches = App::new("Advent of Code 2019")
.version("0.1")
.arg(Arg::with_name("challenge")
.short("c")
.long("challenge")
.value_name("CHALLENGE")
.help("Challenge id from 1 (1st day, 1st part) to 50 (25th day, 2nd part).")
.required(true)
.takes_value(true)
.min_values(1)
.max_values(50))
.arg(Arg::with_name("input")
.short("i")
.long("input")
.value_name("INPUT")
.help("Input file, ex `input/day1`.")
.required(true)
.takes_value(true))
.get_matches();
let input = matches.value_of("input").unwrap();
let challenge = value_t!(matches, "challenge", usize).unwrap() - 1;
let input_file = File::open(input).expect("Unable to open input file");
let reader = BufReader::new(input_file);
let challenges = [
day1::part1, day1::part2,
day2::part1, day2::part2,
day3::part1, day3::part2,
day4::part1, day4::part2,
day5::part1, day5::part1,
];
if let Some(f) = challenges.get(challenge) {
println!("Running day {}, part {}", challenge / 2 + 1, challenge % 2 +1);
f(reader);
} else {
println!("Challenge {}, part {} not unimplemented", challenge / 2 + 1, challenge % 2 + 1)
}
}