1use crate::util::iter::*;
9use crate::util::parse::*;
10
11pub fn parse(input: &str) -> Vec<u32> {
12 input.iter_unsigned().collect()
13}
14
15pub fn part1(input: &[u32]) -> usize {
16 count(input.iter().copied())
17}
18
19pub fn part2(input: &[u32]) -> usize {
20 let first = count(input.iter().copied().step_by(3));
21 let second = count(input.iter().copied().skip(1).step_by(3));
22 let third = count(input.iter().copied().skip(2).step_by(3));
23 first + second + third
24}
25
26fn count(iter: impl Iterator<Item = u32>) -> usize {
27 iter.chunk::<3>().filter(|&[a, b, c]| a + b > c && a + c > b && b + c > a).count()
28}