‹ back to the board

Saturday, October 31

Novicesyntax & basics

The Waystones of the Ysmar Road

The Pathwardens' Guild of Bitwick is cutting a road through the wild to the ruined Temple of Ysmar. Every camp along the road gets a carved waystone. The scouts report each camp's distance from the town gate in miles, and that distance may be fractional. The waystones are carved only in whole leagues, and one league is exactly 3 miles.

Write waystoneLeagues(miles).

  • miles is a non-negative number, either whole or fractional.
  • The function returns an integer: the distance in leagues (miles / 3), rounded to the nearest whole number.
  • If the league distance lies exactly halfway between two whole numbers, round up. For example, 2.5 leagues is carved as 3.
  • numeric conversion and rounding
  • Novice

examples

  1. case 1miles of 7.53 (7.5 miles is exactly 2.5 leagues, and halves round up)
  2. case 2miles of 52 (about 1.67 leagues)
  3. case 3miles of 1.40 (about 0.47 leagues, which is less than half a league)
  4. case 4miles of 13.55 (exactly 4.5 leagues, which rounds up to 5, not down to 4)
reward
150 XP
signature
waystoneLeagues
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 half rounds up
  • rounds down below half
  • rounds up above half
  • zero miles
  • half a league becomes one
  • even-neighbour half still rounds up
  • under half a league is zero
  • long whole distance
  • fractional just under half
The Waystones of the Ysmar Road · bitwick