Countdown to Warp
Stardate 55124.0 ยท UES Magnanimous
Briefing
The Captain enjoys the countdown before a warp jump. It is, he says, "the one bit of theatre we are still allowed". Ensign Tannenbaum's new countdown routine announces the starting number over and over and then says "engage", which the Captain has described as "less theatre, more a man shouting a number".
The routine should count down from the starting number to one, each followed by three dots and a space, and finish with the word engage. From zero, it should simply say engage. The Captain has been extremely clear about the dots.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขFrom five: '5... 4... 3... 2... 1... engage'
- โขFrom one: '1... engage'
- โขFrom zero: just 'engage'
- โขFrom three
- โขFrom ten, and the double digits do not break the spacing
Objective
Write countdown(n): return a single string counting down from
n to 1, each number followed by "... ", and ending with
"engage". So countdown(3) is
"3... 2... 1... engage", and countdown(0) is
"engage".
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write countdown(n: u32) -> String: count down from n to
1, each number followed by "... ", ending with "engage". So
countdown(3) is "3... 2... 1... engage", and
countdown(0) is "engage".
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Loop from n down to 1, collecting each number followed by '... ', then add 'engage'. Building a list of parts and joining them is tidier than concatenating in the loop, and it makes the zero case fall out for free.
Debrief
"5... 4... 3... 2... 1... engage." The Captain has run it three times for no operational reason and Ensign Tannenbaum has been permitted to press the button once, supervised. Lt. Skree has asked what the dots are for. Nobody has a good answer.