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).
levelsis a list of integers: the measurement of each barrel, in row order from the door.capis 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.
examples
- case 1
levels of [3, 7, 7, 2], cap of 7[2, 3] — the second and third barrels, counting the one by the door as 1 - case 2
levels of [1, 2, 3], cap of 10[] — nothing in the row reaches the capacity - case 3
levels of [0, 0], cap of 0[1, 2] — a measurement equal to the capacity counts as full
- reward
- 120 XP
- signature
fullBarrels
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