blob: 46b90776f4a745fea8578d38dbff53ce65ccb0e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
pub fn run(input: String) {
let count_overlaps = input.lines().map(|line| {
let (r1s, r2s) = line.split_once(",").expect("couldn't split on comma");
let (r1starts,r1ends) = r1s.split_once("-").expect("r1s no delimiter -");
let (r2starts,r2ends) = r2s.split_once("-").expect("r2s no delimiter -");
let r1start: u32 = r1starts.parse().expect("r1starts not a u32");
let r1end: u32 = r1ends.parse().expect("r1ends not a u32");
let r2start: u32 = r2starts.parse().expect("r2starts not a u32");
let r2end: u32 = r2ends.parse().expect("r2ends not a u32");
// fully contained (i.e. r1 is fully inside r2 or vice versa)
//let b1in2 = r1start >= r2start && r1end <= r2end;
//let b2in1 = r2start >= r1start && r2end <= r1end;
//return b1in2 || b2in1;
// partially contained (i.e. at least one end of r1 is contained in r2, or vice versa)
let e1 = r1start >= r2start && r1start <= r2end;
let e2 = r1end >= r2start && r1end <= r2end;
let e3 = r2start >= r1start && r2start <= r1end;
let e4 = r2end >= r1start && r2end <= r1end;
let res = e1 || e2 || e3 || e4;
//println!("{}: {}", line, res);
res
})
.filter(|x| {*x})
.count();
println!("Day 4: {}", count_overlaps);
}
|