The Duty Roster
Stardate 55137.3 ยท UES Magnanimous
Briefing
The watch rotation is a list of names, in order, and after the last name it goes back to the first. This is what a rotation is. The current routine, asked who follows the last name on the list, returns nothing, and on two occasions this month the bridge has been unattended for a full shift, during one of which Gerald was, technically, in command.
Chief T'Kala wants: given the roster and the person currently on watch, the next person, wrapping around at the end. If the current person is not on the roster at all, return nothing, because that is a different problem and she wants to hear about it.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขThe next name in the middle of the roster
- โขAfter the last name comes the first
- โขA roster of one wraps to itself
- โขSomeone not on the roster: nothing
- โขAn empty roster: nothing
Objective
Write next_on_duty(roster, current): roster is a list of
names in rotation order. Return the name that follows current, wrapping from
the last name back to the first. Return None if current is
not in the roster.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write next_on_duty(roster: &[&str], current: &str) ->
Option<String>: the name that follows current in rotation
order, wrapping from the last back to the first. None if
current is not in the roster.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Find the position of the current name. If it is not there, return nothing. Otherwise the answer is at position plus one, modulo the length, which is what makes the last one wrap to the first.
Debrief
The rotation wraps. Nobody is following Gerald any more, and Gerald has been formally relieved of command with a small ceremony that Chief T'Kala insists was "not a joke". The contact is now close enough to see hull plating. It has the same dent as ours.