‹ back to the board

Thursday, October 22

Apprenticelogic & control flow

The Glass-Bells of Oskerrin Belfry

High above the moor stands Oskerrin Belfry, whose glass bells ring by themselves at midnight. The Wardens of the Hollow Watch want each night's peal recorded so the haunting can be studied. The ringing is long and repetitive, so the record is kept in runs: an unbroken stretch of the same bell struck again and again is written once, with how many times it rang.

Write pealRuns(strikes).

  • strikes is a list of strings, the name of the bell for each strike, in the order they rang. It may be empty.
  • Return a list of runs, in the order they occurred. Each run is a two-element list [name, count], where name is a bell name (string) and count is a positive integer.
  • A run is a maximal stretch of consecutive strikes with the same name. If the same bell rings again after a different bell, that starts a new run.
  • Names are compared exactly; case matters, so "Tenor" and "tenor" are different bells.
  • An empty strikes list returns an empty list.
  • grouping and partitioning
  • Apprentice

examples

  1. case 1strikes of "Tenor", "Tenor", "Treble", "Tenor"[["Tenor", 2], ["Treble", 1], ["Tenor", 1]] - the Tenor's return after the Treble starts a fresh run
  2. case 2strikes of "Bourdon", "Bourdon", "Bourdon"[["Bourdon", 3]]
  3. case 3no strikes at all (an empty list)[] - an empty record
reward
200 XP
signature
pealRuns
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…
  • returning bell starts new run
  • empty peal
  • single strike
  • one long run
  • all different
  • case matters
  • long mixed peal ending in a run
The Glass-Bells of Oskerrin Belfry · bitwick