‹ back to the board

Friday, November 6

Novicesyntax & basics

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:

  • cargo is the skiff's total load in stones, sandbags included (an integer, 0 or more).
  • lift is the most weight in stones the envelope can raise (an integer, 0 or more).
  • bag is the weight in stones of one sandbag (an integer, at least 1).

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.

  • simple arithmetic
  • Novice

examples

  1. case 1cargo of 120, lift of 100, bag of 73 (the skiff is 20 stones over; two bags shed only 14, so a third is needed)
  2. case 2cargo of 130, lift of 100, bag of 103 (exactly 30 stones over, exactly three bags)
  3. case 3cargo of 100, lift of 100, bag of 50 (a load equal to the lift can already rise)
reward
140 XP
signature
ballastCount
not yet run

TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.

loading the editor…
  • 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
The Ballast-Count of the Corrandel Sky-Skiff · bitwick