‹ back to the board

Wednesday, September 2

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.

  • candles is an integer, 0 or greater.
  • size is an integer, 1 or greater.
  • crate and spare are integers, 0 or greater.
  • The return value is an integer.
  • simple arithmetic
  • Novice

examples

  1. case 1candles of 30, size of 12, crate of 100, spare of 7242 — two full crates (200 coins) and 6 loose candles (42 coins)
  2. case 2candles of 7, size of 12, crate of 100, spare of 749 — no crate can be filled, so all 7 are sold loose
  3. case 3candles of 24, size of 12, crate of 100, spare of 7200 — two full crates and nothing left over
reward
130 XP
signature
crateTakings
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…
  • 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
The Chandler's Crates · bitwick