Overlapping Watches
Stardate 55138.8 ยท UES Magnanimous
Briefing
To line up the other ship's log with ours, Lt. Skree needs to know whether two stardate ranges overlap. Each range is a start and an end, and both ends are inclusive: a range from 10 to 12 includes 12.
The argument is about ranges that touch. Skree says a range ending at 12 and a range starting at 12 share a moment and therefore overlap. Commander Raghunathan agrees, but wanted it written down, because "the last time we didn't write it down, we got a turbolift that stops one deck short". It is written down. Touching counts.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขClearly overlapping ranges
- โขClearly separate ranges
- โขRanges that touch at exactly one point overlap, because ends are inclusive
- โขOne range entirely inside the other
- โขThe same overlap in the other order
Objective
Write overlaps(a, b): a and b are
(start, end) tuples with start <= end, both ends
inclusive. Return True if the ranges share at least one
point.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write overlaps(a: (f64, f64), b: (f64, f64)) -> bool: each is
(start, end) with start <= end, both ends
inclusive. Return true if the ranges share at least one
point.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Two inclusive ranges overlap when each one starts no later than the other ends: a_start <= b_end and b_start <= a_end. Getting the touching case right is a matter of <= versus <.
Debrief
The two logs line up. There is a nineteen-year gap in the middle, and on our side of the gap, an entry that reads "pressure|flow mismatch". On theirs, the same entry, the same stardate, the same handwriting. Skree has removed the word "pending" from the file entirely.