aoc2021/src/day01.rs

30 lines
614 B
Rust

use itertools::Itertools;
const INPUT: &str = include_str!("../inputs/01");
fn input_numbers() -> impl Iterator<Item = usize> {
INPUT.lines().filter_map(|s| s.parse::<usize>().ok())
}
fn part_1() -> usize {
input_numbers()
.tuple_windows()
.filter(|(a, b)| b > a)
.count()
}
fn part_2() -> usize {
input_numbers()
.tuple_windows()
.map(|(a, b, c)| a + b + c)
.tuple_windows()
.filter(|(a, b)| b > a)
.count()
}
pub fn main() {
println!("Day 1:");
println!(" Part 1: {}", part_1());
println!(" Part 2: {}", part_2());
}