‹ back to the board

Sunday, September 6

Apprenticelogic & control flow

The Gate-Warden's Five Seals

The night gate of bitwick opens for a carved inscription, and the warden checks every one against five seals cut into the doorpost. Carters bring their tally-boards to the inn hoping to learn which seal turns them away, since the warden reports only the first failure and nothing further.

You are given inscription, a string. Check it against the five rules in this order and stop at the first one it breaks:

1. "length" — the inscription must be at least 6 and at most 12 characters long. 2. "charset" — every character must be a lowercase letter a–z or a hyphen -. 3. "vowel" — the inscription must contain at least one of a, e, i, o, u. 4. "run" — no character may appear three or more times in a row. 5. "edge" — the first character must not be a hyphen, and neither must the last.

checkInscription(inscription) returns the code string of the first rule in that order that the inscription breaks. If it breaks none of the five, return "open".

  • input validation branches
  • Apprentice

examples

  1. case 1inscription of "brrr-mill""run" — the length is fine, the characters are all allowed, and there is an `i`, but `rrr` is three of a kind in a row
  2. case 2inscription of "aaa""length" — it also has a run of three, but the length seal is checked first and reports 3 characters as too short
  3. case 3inscription of "oakwood-""edge" — eight allowed characters with vowels and no runs, but the last character is a hyphen
  4. case 4inscription of "mill-stone-x""open" — twelve characters, all allowed, vowels present, the longest repeat is `ll`, and neither end is a hyphen
reward
220 XP
signature
checkInscription
not yet run

TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.

loading the editor…
  • empty inscription is too short
  • exactly twelve characters passes every seal
  • uppercase letter fails the charset seal
  • digit fails the charset seal
  • no vowel anywhere
  • triple letter is a run
  • double letter is allowed
  • leading hyphen fails the edge seal
  • trailing hyphen fails the edge seal
  • length is reported before the run
  • charset is reported before run and edge
  • thirteen characters is too long
  • exactly six characters is accepted
The Gate-Warden's Five Seals · bitwick