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".
examples
- case 1
inscription 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 - case 2
inscription of "aaa""length" — it also has a run of three, but the length seal is checked first and reports 3 characters as too short - case 3
inscription of "oakwood-""edge" — eight allowed characters with vowels and no runs, but the last character is a hyphen - case 4
inscription 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
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- 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