‹ back to the board

Saturday, October 24

Novicesyntax & basics

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):

  • n is an integer, n >= 0, the number of adventurers in the party.
  • capacity is 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.

  • simple arithmetic
  • Novice

examples

  1. case 1n of 10, capacity of 43 (four cross, then four more, then the last two)
  2. case 2n of 12, capacity of 43 (three full crossings, nobody left over)
  3. case 3n of 0, capacity of 50
reward
140 XP
signature
crossingsNeeded
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…
  • 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
The Vine-Bridge of Feyhallow Canopy · bitwick