‹ back to the board

Tuesday, September 22

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).

  • jugs is an integer, 0 or greater: how many jugs are on the shelf.
  • size is 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.

  • simple arithmetic
  • Novice

examples

  1. case 1jugs of 29, size of 12[2, 5] — two full barrels, five jugs still on the shelf
  2. case 2jugs of 24, size of 12[2, 0] — an exact fit, nothing left over
  3. case 3jugs of 7, size of 12[0, 7] — not enough for a single barrel
  4. case 4jugs of 0, size of 5[0, 0]
reward
120 XP
signature
tallyBarrels
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…
  • 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
The Cooper's Tally at the Brimming Barrel · bitwick