use std::ops::RangeInclusive; use aoc_runner_derive::{aoc as aoc_run, aoc_generator}; type Contents = (RangeInclusive, RangeInclusive); #[aoc_generator(day4)] fn parse_input(input: &str) -> Vec { let mut out = Vec::with_capacity(input.len()); for line in input.lines() { let mut split = line.split(','); let a = split.next().unwrap(); let b = split.next().unwrap(); let mut asplit = a.split('-'); let mut bsplit = b.split('-'); let alo = asplit.next().unwrap().parse().unwrap(); let ahi = asplit.next().unwrap().parse().unwrap(); let blo = bsplit.next().unwrap().parse().unwrap(); let bhi = bsplit.next().unwrap().parse().unwrap(); out.push(((alo..=ahi), (blo..=bhi))); } out } #[aoc_run(day4, part1)] fn part1(scheds: &[Contents]) -> u32 { let mut out = 0; for (a, b) in scheds { if (a.contains(b.start()) && a.contains(b.end())) || (b.contains(a.start()) && b.contains(a.end())) { out += 1; } } out } #[aoc_run(day4, part2)] fn part2(scheds: &[Contents]) -> u32 { let mut out = 0; for (a, b) in scheds { if (a.contains(b.start()) || a.contains(b.end())) || (b.contains(a.start()) || b.contains(a.end())) { out += 1; } } out }