‹ back to the board

Sunday, October 4

Apprenticelogic & control flow

The Rising Storms of the Brasswind Spires

High on the Brasswind Spires, the Weatherwrights' Lodge keeps a record of every storm that breaks over the peaks. Each thunderclap is written down as an integer loudness, in the order it was heard. The Lodge pays a bounty to anyone who can cut a storm's record into its rising rolls, so the storm-readers can study how each surge of thunder built.

A rising roll is a run of consecutive thunderclaps in which every clap is strictly louder than the one immediately before it. Each roll is made as long as possible.

Write risingRolls(claps), where claps is a list of integers giving the loudness of each thunderclap in order.

Return a list of lists of integers: the claps split into consecutive rising rolls, in their original order.

  • Joining the rolls end to end gives back claps exactly.
  • Within each roll, every value is strictly greater than the value before it.
  • A clap that is equal to or quieter than the clap immediately before it begins a new roll.
  • A roll may contain a single clap.
  • If claps is empty, return an empty list.
  • grouping and partitioning
  • Apprentice

examples

  1. case 1claps of [3, 5, 9, 2, 4, 4, 7][[3, 5, 9], [2, 4], [4, 7]] - the 2 is quieter than the 9, and the second 4 does not rise above the first
  2. case 2claps of [6, 6, 6][[6], [6], [6]] - equal claps never rise, so each stands alone
  3. case 3claps of [] (a storm that never broke)[]
reward
210 XP
signature
risingRolls
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…
  • mixed storm with a tie
  • empty record
  • single clap
  • strictly falling
  • one long rise
  • all equal
  • negative loudness
  • drop at the very end
The Rising Storms of the Brasswind Spires · bitwick