Novicesyntax & basics
The Silent Ferryman of Ravenmouth Ford
At Ravenmouth Ford the river runs black and fast, and only one boat crosses it: the raft of the Silent Ferryman, a hooded figure whom the Wayfarers' Guild has hired to carry its adventurers to the far bank. The Guild wants a quick reckoning of who the Ferryman will take, so that no member walks the long mud road to the ford for nothing.
The Ferryman's terms are fixed:
- Every passenger must pay a fare of at least 3 coins.
- Daytime runs from hour 6 up to, but not including, hour 20. Every other hour (20 through 23, and 0 through 5) is night.
- At night, a passenger must also be carrying a lantern. By day, a lantern makes no difference.
Write mayCross(hour, lantern, coins) where:
houris an integer from 0 to 23, the hour the traveller arrives at the ford.lanternis a boolean, true if the traveller carries a lantern.coinsis a non-negative integer, the coins the traveller offers.
Return true if the Ferryman will carry the traveller under the terms above, and false otherwise.
examples
- case 1
hour of 21, carrying a lantern, 3 coinstrue - it is night, but the lantern and the fare are both there - case 2
hour of 20, no lantern, 7 coinsfalse - hour 20 is already night, and there is no lantern - case 3
hour of 12, carrying a lantern, 2 coinsfalse - the fare is one coin short
- reward
- 150 XP
- signature
mayCross
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- noon without lantern, exact fare
- night without lantern
- night with lantern, exact fare
- day with lantern but short fare
- hour 20 is night
- hour 6 is day
- hour 5 is night even when rich
- midnight with lantern but no coins
- last daytime hour
- hour 23 with lantern