The Bone-Sledges of Hrimvald Glacier
Beyond the last waystone, the only road to the Hollow Thrones of Hrimvald runs across a glacier no one may cross on foot. The Sledgewardens of Hrimvald keep a line of bone-sledges for the crossing, each drawn by a team of white elk. The Wardens will not put more riders on a sledge than it has seats, and every sledge they send out makes the full crossing, however many riders it carries.
An expedition company has posted this contract: before they set out, they need to know how many sledges to hire so that everyone gets across in one departure.
Write sledgesNeeded(party, seats), where:
partyis a non-negative integer: the number of adventurers who must cross.seatsis a positive integer (at least 1): the most riders one sledge can carry.
Return an integer: the smallest number of sledges that together have at least party seats. If party is 0, return 0.
examples
- case 1
party of 7, seats of 33 (two full sledges of 3, and one more carrying the last rider) - case 2
party of 9, seats of 33 (three full sledges, none left over) - case 3
party of 0, seats of 40
- reward
- 130 XP
- signature
sledgesNeeded
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- leftover rider needs an extra sledge
- exact fit needs no extra sledge
- empty party hires nothing
- single rider on a large sledge
- one seat per sledge
- party smaller than seats
- huge expedition