macro-ify matching days and parts
This commit is contained in:
parent
0fb63e65e9
commit
bf6b034768
@ -1,7 +1,7 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// Increments count if each sample is larger than the previous.
|
||||
pub fn day1_p1(input: String) {
|
||||
pub fn part1(input: String) {
|
||||
let mut prev = None;
|
||||
let mut count: u32 = 0;
|
||||
for line in input.lines() {
|
||||
@ -22,7 +22,7 @@ pub fn day1_p1(input: String) {
|
||||
/// 3-sample windowing average (no need to average, just use sum here)
|
||||
///
|
||||
/// We need to start comparing when we have all of
|
||||
pub fn day1_p2(input: String) {
|
||||
pub fn part2(input: String) {
|
||||
let mut storage = VecDeque::with_capacity(5);
|
||||
let mut count = 0;
|
||||
|
||||
|
40
src/main.rs
40
src/main.rs
@ -36,29 +36,7 @@ fn main() {
|
||||
let input = read_input(day).unwrap();
|
||||
|
||||
// TODO macro-ify
|
||||
match day {
|
||||
1 => match part {
|
||||
1 => day1::day1_p1(input),
|
||||
2 => day1::day1_p2(input),
|
||||
_ => (),
|
||||
},
|
||||
2 => match part {
|
||||
1 => day2::part1(input),
|
||||
2 => day2::part2(input),
|
||||
_ => (),
|
||||
},
|
||||
3 => match part {
|
||||
1 => day3::part1(input),
|
||||
2 => day3::part2(input),
|
||||
_ => (),
|
||||
},
|
||||
4 => match part {
|
||||
1 => day4::part1(input),
|
||||
2 => day4::part2(input),
|
||||
_ => (),
|
||||
},
|
||||
_ => println!("Day {} not completed yet!", day),
|
||||
}
|
||||
match_days!(1, day1, 2, day2, 3, day3, 4, day4);
|
||||
}
|
||||
|
||||
// TODO do the inputs ever change inside of a day?
|
||||
@ -66,3 +44,19 @@ fn main() {
|
||||
fn read_input(day: u8) -> std::io::Result<String> {
|
||||
std::fs::read_to_string(format!("inputs/day{}", day))
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! match_days {
|
||||
( $($num:expr, $day:ident),* ) => {
|
||||
match day {
|
||||
$(
|
||||
$num => match part {
|
||||
1 => $day::part1(input),
|
||||
2 => $day::part2(input),
|
||||
_ => println!("Part {} invalid!", part),
|
||||
},
|
||||
)*
|
||||
_ => println!("Day {} not completed yet!", day),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user