Day 4, puzzle 2
This commit is contained in:
parent
b014865ff2
commit
d1a30ea629
9
src/bin/d4p2.rs
Normal file
9
src/bin/d4p2.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use aoc22::{day4, util};
|
||||
|
||||
pub fn main() {
|
||||
let assignments = day4::parse_assignments(&util::parse_input());
|
||||
|
||||
let overlapping = assignments.iter().filter(|a| a.0.overlaps(&a.1)).count();
|
||||
|
||||
println!("{} assignments overlap", overlapping);
|
||||
}
|
@ -10,6 +10,10 @@ impl Assignment {
|
||||
pub fn contains(&self, other: &Self) -> bool {
|
||||
self.lower_bound <= other.lower_bound && self.upper_bound >= other.upper_bound
|
||||
}
|
||||
|
||||
pub fn overlaps(&self, other: &Self) -> bool {
|
||||
self.lower_bound <= other.upper_bound && self.upper_bound >= other.lower_bound
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_assignments(input: &String) -> Vec<(Assignment, Assignment)> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user