diff --git a/src/main.rs b/src/main.rs index 3574418..90e5250 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ fn parse_range(string: &str) -> Range left.parse().unwrap() .. right.parse().unwrap() } +#[allow(dead_code)] fn part1() { let mut pairs_fully_contained = 0; @@ -34,6 +35,27 @@ fn part1() println!("There are {} pairs in which one range is fully contained in the other one", pairs_fully_contained); } -fn main() { - part1() +fn part2() +{ + let mut overlapping_pairs = 0; + for slice in DATA.split("\n") + { + if slice.is_empty() { continue; } + + let (left, right) = slice.split_once(",").expect("Input data is not correctly structured"); + + let left_range = parse_range(left); + let right_range = parse_range(right); + + if left_range.start <= right_range.end && right_range.start <= left_range.end + { + overlapping_pairs += 1; + } + } + println!("There are {} pairs where ranges overlap", overlapping_pairs); +} + +fn main() { + //part1() + part2() }