‹ back to the board

Thursday, September 17

Novicesyntax & basics

The Weighbridge at the Wool Market

The wool market's weighbridge is honest to a fault: it reports a fleece-load in stones with whatever fraction it finds. The toll clerk's ledger, however, has room only for whole stones, and the guild's rule for filling it is fixed — write the nearest whole number of stones, and when a load sits exactly halfway between two whole numbers, write the larger one.

Write wholeStones(weight).

  • weight is a number (possibly with a fractional part), and is never negative.
  • Return an integer: the whole number of stones the clerk writes in the ledger, being the nearest whole number to weight, with an exact half rounding upward.
  • numeric conversion and rounding
  • Novice

examples

  1. case 1weight of 4.24
  2. case 2weight of 2.53 (an exact half goes up, never down)
  3. case 3weight of 0.51
  4. case 4weight of 99
reward
140 XP
signature
wholeStones
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…
  • fraction below a half rounds down
  • exact half rounds up
  • another exact half rounds up
  • fraction above a half rounds up
  • just under a half rounds down
  • smallest half is still a half
  • an empty cart
  • already a whole number of stones
The Weighbridge at the Wool Market · bitwick