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).
weightis a non-negative number, possibly with a fractional part (stones).rateis 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.
examples
- case 1
weight of 3.25, rate of 413 — the fare is exactly 13 coins - case 2
weight of 2.5, rate of 13 — the fare is exactly two and a half coins, and an exact half rounds up - case 3
weight of 4.2, rate of 28 — 8.4 coins rounds down to 8 - case 4
weight of 0, rate of 70
- reward
- 140 XP
- signature
ferryFare
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