‹ back to the board

Saturday, October 17

Apprenticelogic & control flow

The Herald-Stones of Gallowmere Pass

High in Gallowmere Pass stands a line of herald-stones, one after another along the old road. The first stone was carved with a string of digits. Each later stone was carved by the Pass Wardens reading the stone before it aloud, left to right, one run at a time. A run is a maximal block of consecutive identical digits. For each run they carve two things: how many digits the run contains, written in ordinary decimal, and then the digit itself.

A run's length is written in full, even when it is 10 or more. For example, a run of twelve 0s is carved as 120.

The Wardens' Lodge offers a bounty to whoever can say what is carved on any stone down the line without climbing the pass.

Write carveStone(seed, n):

  • seed is a non-empty string of decimal digits (0-9), the carving on the first stone.
  • n is a non-negative integer, the number of stones past the first.

Return the carving on the stone n steps after the first, as a string. Each step applies the reading rule above exactly once to the previous carving. When n is 0, return seed unchanged.

  • iterative sequence generation
  • Apprentice

examples

  1. case 1seed of "1", n of 4"111221" (the stones read 1, 11, 21, 1211, 111221)
  2. case 2seed of "3322251", n of 1"23321511" (two 3s, three 2s, one 5, one 1)
  3. case 3seed of "1111111111" (ten 1s), n of 1"101" (a run of ten is carved as 10, then the digit 1)
  4. case 4seed of "7", n of 0"7"
reward
220 XP
signature
carveStone
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
  • mixed runs one step
  • run of ten
  • classic seed six steps
  • self-describing seed stays fixed
  • zero digit seed
  • distinct digits two steps
  • twelve zeros two steps
The Herald-Stones of Gallowmere Pass · bitwick