04.rs
1 #![feature(test)] 2 3 type Input = Vec<(u8, u8, u8, u8)>; 4 5 fn setup(input: &str) -> Input { 6 input 7 .lines() 8 .map(|line| { 9 let mut it = line.split(&[',', '-']).map(|x| x.parse().unwrap()); 10 (|| Some((it.next()?, it.next()?, it.next()?, it.next()?)))().unwrap() 11 }) 12 .collect() 13 } 14 15 fn part1(input: &Input) -> usize { 16 input 17 .iter() 18 .filter(|(a, b, c, d)| a <= c && d <= b || c <= a && b <= d) 19 .count() 20 } 21 22 fn part2(input: &Input) -> usize { 23 input.iter().filter(|(a, b, c, d)| d >= a && c <= b).count() 24 } 25 26 aoc::main!(2022, 4, ex: 1);