The Ballast-Count of the Corrandel Sky-Skiff
The sky-skiff *Gannet's Wake* lifts off from Corrandel Heights at dawn to carry an expedition over the Veshmoor cliffs. Her gas-envelope can raise only so much weight. If she is overladen, her crew must throw sandbags of ballast overboard until she can rise. The Aeronauts' Guild pays for a reckoning of how many bags must go.
Write ballastCount(cargo, lift, bag), where:
cargois the skiff's total load in stones, sandbags included (an integer,0or more).liftis the most weight in stones the envelope can raise (an integer,0or more).bagis the weight in stones of one sandbag (an integer, at least1).
Return an integer: the smallest number of whole sandbags that must be thrown overboard so that the remaining load is at most lift. If cargo is already at most lift, return 0.
There are always enough sandbags aboard to make up any excess. Sandbags cannot be split.
examples
- case 1
cargo of 120, lift of 100, bag of 73 (the skiff is 20 stones over; two bags shed only 14, so a third is needed) - case 2
cargo of 130, lift of 100, bag of 103 (exactly 30 stones over, exactly three bags) - case 3
cargo of 100, lift of 100, bag of 50 (a load equal to the lift can already rise)
- reward
- 140 XP
- signature
ballastCount
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- excess with a remainder needs an extra bag
- excess divides evenly
- load exactly equal to lift
- load under lift
- one stone over with heavy bags
- empty skiff with no lift
- single-stone bags
- no lift at all