mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 05:40:32 +01:00
Update 2018 skeleton.
This commit is contained in:
@@ -35,10 +35,10 @@ pub fn prime_sieve(dest: &mut[bool]) {
|
|||||||
/// be easily run from the main program.
|
/// be easily run from the main program.
|
||||||
pub trait Solution {
|
pub trait Solution {
|
||||||
/// Solve the first part of the day
|
/// Solve the first part of the day
|
||||||
fn part1(&mut self, input: Box<io::Read>);
|
fn part1(&mut self, input: &mut io::Read) -> String;
|
||||||
|
|
||||||
/// Solve the second part of the day
|
/// Solve the second part of the day
|
||||||
fn part2(&mut self, input: Box<io::Read>);
|
fn part2(&mut self, input: &mut io::Read) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ impl Day1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl common::Solution for Day1 {
|
impl common::Solution for Day1 {
|
||||||
fn part1(&mut self, input: Box<io::Read>) {
|
fn part1(&mut self, input: &mut io::Read) -> String {
|
||||||
println!("Not implemented");
|
panic!("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(&mut self, input: Box<io::Read>) {
|
fn part2(&mut self, input: &mut io::Read) -> String {
|
||||||
println!("Not implemented");
|
panic!("Not implemented");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,15 +38,15 @@ fn main() {
|
|||||||
let day: i32 = (&matches.value_of("day").unwrap()).parse()
|
let day: i32 = (&matches.value_of("day").unwrap()).parse()
|
||||||
.expect("Invalid int");
|
.expect("Invalid int");
|
||||||
let mut implementation = get_impl(day);
|
let mut implementation = get_impl(day);
|
||||||
let data: Box<io::Read> = match matches.value_of("input") {
|
let mut data: Box<io::Read> = match matches.value_of("input") {
|
||||||
Some(filename) => { Box::new(fs::File::open(filename).unwrap()) }
|
Some(filename) => { Box::new(fs::File::open(filename).unwrap()) }
|
||||||
None => { Box::new(io::stdin()) }
|
None => { Box::new(io::stdin()) }
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches.is_present("part2") {
|
if matches.is_present("part2") {
|
||||||
implementation.part2(data)
|
println!("{}", implementation.part2(&mut data));
|
||||||
} else {
|
} else {
|
||||||
implementation.part1(data)
|
println!("{}", implementation.part1(&mut data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user