The Vine-Bridge of Feyhallow Canopy
High in Feyhallow Canopy, the Thornwarden rangers keep a single living vine-bridge strung between two of the great trees. It is the only way across to the far tree. The Thornwardens have posted this commission: tell each arriving party how many crossings it will take to get every member to the far side.
The bridge can bear at most capacity adventurers at once. A single crossing carries any number of adventurers from 1 up to capacity from the near tree to the far tree. Nobody ever walks back, and nobody needs to.
Write crossingsNeeded(n, capacity):
nis an integer,n >= 0, the number of adventurers in the party.capacityis an integer,capacity >= 1, the most adventurers the bridge can hold in one crossing.
Return an integer: the smallest number of crossings needed to get all n adventurers across. A party of 0 needs 0 crossings.
examples
- case 1
n of 10, capacity of 43 (four cross, then four more, then the last two) - case 2
n of 12, capacity of 43 (three full crossings, nobody left over) - case 3
n of 0, capacity of 50
- reward
- 140 XP
- signature
crossingsNeeded
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- remainder needs one more crossing
- exact multiple adds no extra crossing
- empty party
- single adventurer single capacity
- capacity of one
- party smaller than capacity
- one over a multiple
- large party