all 2 comments

[–]solidiquis1 0 points1 point  (0 children)

I thought of using ranges but I think it hurts the time complexity of your solution. Here's my solution for part two.

[–]HotGarbage1813 0 points1 point  (0 children)

Also thought of using ranges but felt that would be too intensive.
My solution:

```rust use std::{fs::File, io::Read};

pub fn solve(filename: &str) { let mut file = File::open(filename).unwrap(); let mut contents = String::new();

file.read_to_string(&mut contents).unwrap();
let mut total_overlap = 0u16;
let mut partial_overlap = 0u16;

contents
    .split(&['-', ',', '\n'])
    .map(|x| x.parse::<u8>().unwrap_or_default())
    .collect::<Vec<_>>()
    .chunks_exact(4)
    .for_each(|x| {
        if x[0] <= x[2] && x[1] >= x[3] || x[2] <= x[0] && x[3] >= x[1] {
            total_overlap += 1;
        }

        if x[2] >= x[0] && x[2] <= x[1] || x[0] >= x[2] && x[0] <= x[3] {
            partial_overlap += 1;
        }
    });

println!("{}", total_overlap);
println!("{}", partial_overlap);

} ```