aoc2021day01

mail@pastecode.io avatar
unknown
rust
3 years ago
1.0 kB
10
Indexable
Never
use aoc::{
    data::{AdventDay, AdventDayStatus},
    solver::AocSolver,
    testing::{aoc_integration_test, aoc_unit_test},
};
use itertools::Itertools;

pub struct Day1;

impl AocSolver for Day1 {
    const ADVENT_DAY: AdventDay = AdventDay::new(1, 2021);

    fn solve(input: &str) -> AdventDayStatus {
        let input: Vec<u32> = input.lines().map(|line| line.parse().unwrap()).collect();
        let part_one = input
            .iter()
            .tuple_windows()
            .filter(|(prev, current)| current > prev)
            .count();
        let part_two = input
            .iter()
            .tuple_windows()
            .filter(|(prev, _, _, current)| current > prev)
            .count();
        AdventDayStatus::two_parts(part_one, part_two)
    }
}

aoc_unit_test!(Day1,
    (example_1,
    indoc::indoc!("
        199
        200
        208
        210
        200
        207
        240
        269
        260
        263
    "), 
    part_one: 7,
    part_two: 5)
);

aoc_integration_test!(Day1);