‹ back to the board

Sunday, September 13

Novicesyntax & basics

The Cooper's Tally of Full Barrels

The cooper of bitwick keeps her cellar barrels in one long row against the north wall, numbered from 1 at the door and counting up as you walk into the dark. Each morning she measures how many pints sit in each barrel and writes the measurements down in order. A barrel counts as full when its measurement is at least the day's stated capacity.

Write fullBarrels(levels, cap).

  • levels is a list of integers: the measurement of each barrel, in row order from the door.
  • cap is an integer: the day's capacity.

Return a list of integers: the 1-based positions of every barrel whose measurement is greater than or equal to cap, in increasing order of position. Return an empty list if no barrel qualifies, or if levels is empty. Do not modify levels.

  • list and array basics
  • Novice

examples

  1. case 1levels of [3, 7, 7, 2], cap of 7[2, 3] — the second and third barrels, counting the one by the door as 1
  2. case 2levels of [1, 2, 3], cap of 10[] — nothing in the row reaches the capacity
  3. case 3levels of [0, 0], cap of 0[1, 2] — a measurement equal to the capacity counts as full
reward
120 XP
signature
fullBarrels
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…
  • two full barrels in the middle
  • empty cellar
  • nothing reaches capacity
  • capacity of zero makes every barrel full
  • single barrel exactly at capacity
  • first and last of a longer row
The Cooper's Tally of Full Barrels · bitwick