The Beacon-Codes of Ostrel Point
Along the black cliffs of Ostrel Point, the Keepers' Guild flashes coded warnings from tower to tower whenever raider sails are sighted. A malformed code can send a whole fleet onto the rocks. The Guild posts a bounty for a checker that inspects each code before it is lit and names exactly what is wrong with it.
Write checkBeacon(code), where code is a string. Return a string: the label of the first rule below that code breaks, checking the rules in the order listed. If it breaks none of them, return "valid".
1. "empty": the code is the empty string. 2. "length": the code is shorter than 4 characters or longer than 12 characters. 3. "symbol": the code contains any character that is not an uppercase ASCII letter A-Z or an ASCII digit 0-9. Lowercase letters, spaces and punctuation all break this rule. 4. "start": the first character of the code is not a letter. 5. "digit": the code contains no digit at all. 6. "repeat": the same character appears three or more times consecutively, in adjacent positions.
A code may break several rules at once. Only the earliest broken rule in this list is reported.
examples
- case 1
code of "KX7R""valid" - case 2
code of "ab" (too short, and lowercase)"length": the length rule comes before the symbol rule - case 3
code of "1234" (starts with a digit, and has digits)"start" - case 4
code of "ZZZ9""repeat": three Z's in a row
- reward
- 220 XP
- signature
checkBeacon
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- empty code
- too short
- too long at thirteen
- minimum length valid
- maximum length valid
- hyphen is a symbol
- lowercase is a symbol
- space is a symbol
- length before symbol
- symbol before start
- starts with digit
- start before digit rule
- no digit
- digit before repeat
- letter repeat
- digit repeat in middle
- repeat at end
- pairs are fine
- non-adjacent repeats are fine
- ordinary valid code