‹ back to the board

Thursday, September 10

Novicesyntax & basics

The Ferryman's Weighing Stone

The ferryman of bitwick will not carry a crate across the river until it sits on his weighing stone and the fare is settled in whole coins.

He reads two things off the stone: the weight of the crate, and the posted rate for the day.

Write ferryFare(weight, rate).

  • weight is a non-negative number, possibly with a fractional part (stones).
  • rate is a non-negative integer (coins charged per stone).

The raw fare is weight multiplied by rate. Return that fare as an integer, rounded to the nearest whole coin, with an exact half always rounded up.

The returned value must be a whole number, not a fraction.

  • numeric conversion and rounding
  • Novice

examples

  1. case 1weight of 3.25, rate of 413 — the fare is exactly 13 coins
  2. case 2weight of 2.5, rate of 13 — the fare is exactly two and a half coins, and an exact half rounds up
  3. case 3weight of 4.2, rate of 28 — 8.4 coins rounds down to 8
  4. case 4weight of 0, rate of 70
reward
140 XP
signature
ferryFare
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…
  • exact whole fare
  • exact half rounds up
  • larger exact half rounds up
  • fraction rounds down
  • fraction rounds up
  • weightless crate
  • free crossing day
  • whole weight and whole rate
The Ferryman's Weighing Stone · bitwick