‹ back to the board

Friday, October 23

Apprenticelogic & control flow

The Echo-Tablets of Mount Durrowen

High on Mount Durrowen, a stairway of carved tablets climbs to a sealed shrine. Each tablet was carved by reading aloud the tablet just below it. The Durrowen Pathwardens pay a bounty to anyone who can say what is carved on a given tablet before they make the climb.

The rule of the stair is exact:

  • Tablet 0 carries the seed.
  • Each later tablet is made from the one before it. Read the previous tablet from left to right and split it into maximal runs of the same digit. For each run, in order, write the length of the run as a decimal number, then the digit itself. Join these pieces together to make the new tablet.

Write echoTablet(seed, steps), where:

  • seed is a non-empty string made only of the digits 0-9.
  • steps is an integer, 0 or greater.

Return the string carved on tablet number steps. When steps is 0, return seed unchanged.

A run's length is written in full decimal. For example, a run of twelve 5s is written as 125.

  • iterative sequence generation
  • Apprentice

examples

  1. case 1seed of "1", steps of 4"111221" (the stair reads 1 → 11 → 21 → 1211 → 111221)
  2. case 2seed of "1111111111" (ten 1s), steps of 1"101" (one run of ten 1s)
  3. case 3seed of "333", steps of 0"333" (tablet 0 is the seed itself)
reward
220 XP
signature
echoTablet
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…
  • classic seed four steps
  • zero steps returns seed
  • single digit one step
  • run of ten written in full
  • run of thirteen nines
  • twenty-two never changes
  • mid-stair seed two steps
  • classic seed six steps
  • seed with zero digit
  • zero steps long seed
The Echo-Tablets of Mount Durrowen · bitwick