Novicesyntax & basics
The Chandler's Crates
The chandler of bitwick has finished her winter pour and needs the market takings worked out before dawn.
Candles travel to market in crates. A crate holds exactly size candles and, when full, sells for crate coins. Any candles left over after the crates are filled are sold one at a time for spare coins each.
Write crateTakings(candles, size, crate, spare), which returns the total number of coins taken: the number of completely full crates multiplied by crate, plus the number of remaining candles multiplied by spare.
candlesis an integer, 0 or greater.sizeis an integer, 1 or greater.crateandspareare integers, 0 or greater.- The return value is an integer.
examples
- case 1
candles of 30, size of 12, crate of 100, spare of 7242 — two full crates (200 coins) and 6 loose candles (42 coins) - case 2
candles of 7, size of 12, crate of 100, spare of 749 — no crate can be filled, so all 7 are sold loose - case 3
candles of 24, size of 12, crate of 100, spare of 7200 — two full crates and nothing left over
- reward
- 130 XP
- signature
crateTakings
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- full crates and a remainder
- fewer candles than one crate holds
- exact multiple, nothing loose
- no candles at all
- crates of one
- exactly one crate
- loose candles are worthless