The Waystones of the Sallowmere Dunes
The Cistern-Wardens of the Sallowmere Dunes pay well for stonecutters. Across the dunes, every caravan route is marked by numbered waystones, and the sandstorms scour the old carvings away each season. The Wardens have posted a commission: recut every waystone with its number, the name of the place it marks, and how many leagues that place lies from the Bitwick road. Every stone must be carved in exactly the same form, so that riders can read them at a glance through blowing sand.
Write carveWaystone(stone, name, leagues), which returns the inscription for one waystone as a string.
Arguments - stone: a non-negative integer, the waystone's number. - name: a non-empty string, the place the stone marks. Use it exactly as given. - leagues: a non-negative integer, the distance in leagues.
Return a string of exactly this form:
Stone NNN: NAME, D UNIT
NNNisstonewritten with leading zeros so that it is at least 3 digits long. A number that already has 3 or more digits is written in full, with no padding and no truncation.NAMEisname, unchanged.Disleagueswritten as a plain integer, with no padding.UNITisleaguewhenleaguesis exactly 1, andleaguesotherwise, including when it is 0.
There is exactly one space after the colon, one space after the comma, and one space between D and UNIT. There is no trailing punctuation.
examples
- case 1
stone 7, name "Ossery Wells", leagues 12"Stone 007: Ossery Wells, 12 leagues" - case 2
stone 1, name "Kettle Rock", leagues 1"Stone 001: Kettle Rock, 1 league" - case 3
stone 1204, name "Last Cistern", leagues 310"Stone 1204: Last Cistern, 310 leagues"
- reward
- 130 XP
- signature
carveWaystone
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- two-digit padding with plural
- singular league
- zero stone and zero leagues
- one leading zero
- four-digit stone not truncated
- exactly three digits
- eleven leagues is plural