Novicesyntax & basics
The Millpond Ferryman's Toll
The ferry at Millpond crosses with grain sacks stacked on its deck, and the ferryman is paid the same coins for every crossing whether the deck is full or holds a single sack.
Write ferryToll(sacks, load, fee):
sacksis a non-negative integer: how many sacks must reach the far bank.loadis an integer of 1 or more: the greatest number of sacks the deck holds in one crossing.feeis a non-negative integer: the coins charged for one crossing.
Return an integer: the total coins owed for carrying all the sacks across, counting one fee per crossing made. Only crossings that carry sacks are counted; the empty trips back are free.
examples
- case 1
sacks of 7, load of 3, fee of 212 sacks... no: 3 crossings (3, 3, 1) at 2 coins each = 6 - case 2
sacks of 6, load of 3, fee of 22 crossings (3, 3) at 2 coins each = 4 - case 3
sacks of 0, load of 4, fee of 50 - the ferry never leaves the bank
- reward
- 130 XP
- signature
ferryToll
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- leftover sacks need an extra crossing
- exact multiple of the deck load
- nothing to carry
- one sack on a wide deck
- a hundred sacks, seven at a time
- a free ferryman
- one sack at a time