Expand description
§Camp Cleanup
This puzzle asks to compute range intersections. To simplify the 2nd part, we can use a trick. Rather than consider each possible case of intersection (overlapping start, overlapping end, completely enclosed or completely enclosing) it’s simpler to check if two ranges don’t overlap then invert.
If a
and b
are the ordered start and end of the first range and c
and d
the ordered
start and end of the second range, then if:
a > d || c > b
the 2 ranges can’t overlap. Using DeMorgan’s laws this can be inverted to:
a <= d && c <= b
to check when two ranges do overlap.
Functions§
- Parse each line into 4 integers.
- Count ranges completely enclosed by each other.
- Count ranges with any intersection.
Type Aliases§
- Pairs 🔒