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())
17}
18
19pub fn part2(input: &[u32]) -> usize {
20 let first = count(input.iter().step_by(3));
21 let second = count(input.iter().skip(1).step_by(3));
22 let third = count(input.iter().skip(2).step_by(3));
23 first + second + third
24}
25
26fn count<'a, I>(iter: I) -> usize
27where
28 I: Iterator<Item = &'a u32>,
29{
30 iter.chunk::<3>().filter(|&[&a, &b, &c]| a + b > c && a + c > b && b + c > a).count()
31}