advent_of_code_2022/days/day04/src/part2.rs

28 lines
691 B
Rust
Raw Normal View History

use crate::utilities::*;
2022-12-04 07:41:09 +01:00
pub fn part2(input: &[(Range, Range)]) -> usize {
input
.iter()
.filter(|tuple| tuple.0.any_overlap(&tuple.1))
.count()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_part2() {
2022-12-04 07:41:09 +01:00
let input = vec![
(Range::new(2, 4), Range::new(6, 8)),
(Range::new(2, 3), Range::new(4, 5)),
(Range::new(5, 7), Range::new(7, 9)),
(Range::new(2, 8), Range::new(3, 7)),
(Range::new(6, 6), Range::new(4, 6)),
(Range::new(2, 6), Range::new(4, 8)),
(Range::new(19, 30), Range::new(5, 18)),
];
assert_eq!(part2(&input), 4);
}
}