Novicesyntax & basics
The Cooper's Tally at the Brimming Barrel
The cooper behind the Brimming Barrel fills her barrels from a row of clay jugs. Every barrel takes the same number of jugs, and she will not cart a barrel to market unless it is completely full — whatever jugs are left after the last full barrel stay on the shelf.
Write tallyBarrels(jugs, size).
jugsis an integer, 0 or greater: how many jugs are on the shelf.sizeis an integer, 1 or greater: how many jugs fill one barrel exactly.
Return a list (array) of exactly two integers: first the number of completely filled barrels, then the number of jugs left over.
examples
- case 1
jugs of 29, size of 12[2, 5] — two full barrels, five jugs still on the shelf - case 2
jugs of 24, size of 12[2, 0] — an exact fit, nothing left over - case 3
jugs of 7, size of 12[0, 7] — not enough for a single barrel - case 4
jugs of 0, size of 5[0, 0]
- reward
- 120 XP
- signature
tallyBarrels
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- leftover jugs remain on the shelf
- exact multiple leaves nothing over
- too few jugs for one barrel
- empty shelf
- barrels of one jug
- a large delivery