‹ back to the board

Saturday, November 7

Apprenticelogic & control flow

The Lamp-Brands of Glimmerdeep Delve

No delver goes down into the Glimmerdeep without a brand stamped on their lantern by the Lampwrights' Guild. The Guild has found forged brands among the lanterns. It offers a commission to whoever will build the inspector that reads a brand and names its first fault.

Write inspectBrand(brand). brand is a string.

A well-formed brand is exactly 7 characters long: - characters 1–2: uppercase letters A–Z (the guild mark), - character 3: a hyphen -, - characters 4–7: digits 0–9.

The last digit is a check digit. It must equal the sum of digits 4, 5 and 6 modulo 10.

"Letter" means only the uppercase letters A–Z, so lowercase letters fail. "Digit" means only 0–9.

Apply these rules in this order. Return the verdict of the first rule the brand fails:

1. "wrong length": the brand is not exactly 7 characters. 2. "bad guild mark": character 1 or character 2 is not an uppercase letter A–Z. 3. "missing hyphen": character 3 is not -. 4. "bad number": any of characters 4–7 is not a digit 0–9. 5. "bad check digit": character 7 does not equal (digit 4 + digit 5 + digit 6) modulo 10.

If the brand passes all five rules, return "sound". The return value is always one of these six strings.

  • input validation branches
  • Apprentice

examples

  1. case 1brand of "QX-4565""sound" (4 + 5 + 6 = 15, and 15 modulo 10 is 5)
  2. case 2brand of "kr_abcd""bad guild mark" (it breaks several rules, but rule 2 is the first it fails)
  3. case 3brand of "KR-1235""bad check digit" (1 + 2 + 3 = 6, not 5)
  4. case 4brand of "KR-12345""wrong length"
reward
220 XP
signature
inspectBrand
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…
  • plain sound brand
  • check digit wraps modulo 10
  • all zeros sound
  • max sum wraps
  • unwrapped sum rejected
  • empty string
  • one too long
  • short garbage is wrong length first
  • lowercase guild letter
  • digit in guild mark
  • many faults reports guild mark
  • underscore instead of hyphen
  • hyphen fault before number fault
  • letter among digits
  • non-digit check position
  • wrong check digit
  • max sum unwrapped wrong
The Lamp-Brands of Glimmerdeep Delve · bitwick