day04: Change implementation for part 2
This will print all overlapping ranges instead of only fully contained ranges.
This commit is contained in:
parent
57b95e8c2c
commit
93e88b94b7
|
@ -16,10 +16,10 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
let range_a = ops::Range { start: range_a_u32[0], end: range_a_u32[1] + 1 };
|
let range_a = ops::Range { start: range_a_u32[0], end: range_a_u32[1] + 1 };
|
||||||
let range_b_u32 = range_strs[1].split("-").map(|x| x.parse::<u32>().unwrap()).collect::<Vec<u32>>();
|
let range_b_u32 = range_strs[1].split("-").map(|x| x.parse::<u32>().unwrap()).collect::<Vec<u32>>();
|
||||||
let range_b = ops::Range { start: range_b_u32[0], end: range_b_u32[1] + 1 };
|
let range_b = ops::Range { start: range_b_u32[0], end: range_b_u32[1] + 1 };
|
||||||
if (range_a.contains(&range_b.start) && range_a.contains(&(range_b.end - 1))) || (range_b.contains(&range_a.start) && range_b.contains(&(range_a.end - 1))) {
|
if range_a.contains(&range_b.start) || range_a.contains(&(range_b.end - 1)) || range_b.contains(&range_a.start) || range_b.contains(&(range_a.end - 1)) {
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("Found {} completely contained ranges.", count);
|
println!("Found {} overlapping ranges.", count);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue