๐Ÿ›ก๏ธ Tactical

Heading: Validated

Stardate 55140.2 ยท UES Magnanimous

Briefing

Welcome to Tactical, which on this ship means the station that says no. Chief T'Kala runs it, and she has a list.

Item one on the list: the helm accepts any heading a person types. Yesterday it accepted "left". Last week it accepted 400, which it treated as 40, and -12, which it treated as a mood. A heading is a whole number from 0 to 359, and the Chief wants text that is anything else to be refused: not corrected, not guessed at, refused, so the person at the helm has to try again. Whitespace around a valid number is fine. Ensign Tannenbaum typed most of the examples.

Mission objectives

ARCHIE checks all five every time you run diagnostics.

  • โ€ขA valid heading is accepted
  • โ€ขWhitespace around a valid heading is fine
  • โ€ขWords are refused
  • โ€ข360 and above are refused, not wrapped
  • โ€ขNegative numbers are refused
Ask Commander Raghunathan for a hint

Trim, then try to convert to a whole number; if that fails, refuse. Then check the range 0 to 359 and refuse anything outside it. Rust's parse::<u16>() already refuses negatives, and .ok()? makes the whole thing three lines.