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
0carries theseed. - 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:
seedis a non-empty string made only of the digits0-9.stepsis an integer,0or 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.
examples
- case 1
seed of "1", steps of 4"111221" (the stair reads 1 → 11 → 21 → 1211 → 111221) - case 2
seed of "1111111111" (ten 1s), steps of 1"101" (one run of ten 1s) - case 3
seed of "333", steps of 0"333" (tablet 0 is the seed itself)
- reward
- 220 XP
- signature
echoTablet
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