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).
milesis 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.
examples
- case 1
miles of 7.53 (7.5 miles is exactly 2.5 leagues, and halves round up) - case 2
miles of 52 (about 1.67 leagues) - case 3
miles of 1.40 (about 0.47 leagues, which is less than half a league) - case 4
miles of 13.55 (exactly 4.5 leagues, which rounds up to 5, not down to 4)
- reward
- 150 XP
- signature
waystoneLeagues
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