The Band-Marks of Sarnavel Eyrie
High on the cliffs of Sarnavel Eyrie, the Falconers' Lodge rings every hunting hawk with a brass band stamped with a mark. Poachers along the cliff paths have taken to stamping false bands onto stolen birds. The Lodge pays a bounty to any adventurer who can sort true marks from forgeries at a glance.
Write checkBand(mark). It takes a string mark and returns a string. Check these rules in this order, and return the word for the first rule that the mark breaks:
1. mark must be exactly 8 characters long. If not, return "length". 2. Characters 1 to 3 must each be an uppercase ASCII letter A-Z. If not, return "letters". 3. Character 4 must be a hyphen -. If not, return "dash". 4. Characters 5 to 8 must each be an ASCII digit 0-9. If not, return "digits". 5. Add the digits in characters 5, 6 and 7, and take the remainder of that sum when divided by 10. Character 8 must equal this remainder. If not, return "check".
If the mark passes all five rules, return "valid".
Characters are counted from 1 at the left. Every test uses plain ASCII characters only.
examples
- case 1
mark of "SAR-9874""valid" (9 + 8 + 7 = 24, remainder 4, and the last digit is 4) - case 2
mark of "Sar-12x5""letters" (lowercase letters break rule 2; the bad digit is never reached) - case 3
mark of "SAR-1235""check" (1 + 2 + 3 = 6, but the last digit is 5) - case 4
mark of "" (empty)"length"
- reward
- 220 XP
- signature
checkBand
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- plain valid mark
- valid mark where tally wraps
- all zeros is valid
- wrong check digit
- unwrapped sum mistaken
- empty mark
- too long
- too short
- lowercase letters
- letters rule before digits rule
- everything wrong but length
- underscore instead of hyphen
- letter among digits
- second hyphen in digit block