The Access Code
Stardate 55150.8 ยท UES Magnanimous
Briefing
The other computer will talk, but it wants an access code set first, and Chief T'Kala has rules for codes. At least eight characters. At least one digit. At least one upper case letter. No spaces. Ensign Tannenbaum's first proposal was "pass", which breaks three of them, and the Chief wants him told about all three at once rather than one at a time across three attempts.
So this checker does not stop at the first problem. It collects every rule the code breaks, in the order the rules are listed, and returns them. A code that breaks nothing returns an empty list, which is how you know it is good. Compare this with the transporter check from last season, which stopped at the first refusal; both shapes are right for different jobs.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขA good code returns no problems
- โขToo short is reported
- โขSeveral problems are all reported, in rule order
- โขA space anywhere is reported
- โขExactly eight characters is long enough
Objective
Write code_problems(code): return a list of the rules the code breaks,
in this order, using these exact strings: "too short" (fewer than 8
characters), "needs a digit", "needs an upper case letter",
"contains a space". A code that breaks nothing returns [].
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write code_problems(code: &str) -> Vec<&'static str>: the
rules the code breaks, in this order, using these exact strings: "too short"
(fewer than 8 characters), "needs a digit", "needs an upper case
letter", "contains a space". A code that breaks nothing returns an
empty vector.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Start with an empty list, test each rule in order, and append the message when a rule fails. Return the list. Do not return early; that is the whole difference from last season's transporter check.
Debrief
Ensign Tannenbaum's fourth proposal passed. It is not "Password1", because Chief T'Kala added a fifth rule on the spot for that. The other computer has accepted the code and asked, in text, whether "the technician" is still aboard. Commander Raghunathan has typed yes.