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).
strikesis 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], wherenameis a bell name (string) andcountis 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
strikeslist returns an empty list.
examples
- case 1
strikes of "Tenor", "Tenor", "Treble", "Tenor"[["Tenor", 2], ["Treble", 1], ["Tenor", 1]] - the Tenor's return after the Treble starts a fresh run - case 2
strikes of "Bourdon", "Bourdon", "Bourdon"[["Bourdon", 3]] - case 3
no strikes at all (an empty list)[] - an empty record
- reward
- 200 XP
- signature
pealRuns
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