The Torch-Tally of Greymantle Delve
The Cartographers' Guild of Bitwick is sending an expedition into Greymantle Delve, a mine shaft abandoned so long ago that no daylight reaches past its mouth. The expedition must carry its own light. The Guild's quartermaster will pay for an exact tally of torches, so that the party neither runs dark nor hauls dead weight.
The torches are lit one at a time. A new torch is lit the moment the previous one burns out. Every torch burns for the same number of minutes. A torch that is only partly used up when the expedition ends still had to be carried, so it counts as a whole torch.
Write torchesNeeded(minutes, burn).
minutesis a non-negative integer: how many minutes the expedition will spend in the Delve.burnis a positive integer (at least 1): how many minutes a single torch burns.
Return an integer: the smallest number of torches whose combined burn time is at least minutes. If minutes is 0, no torches are needed and the answer is 0.
examples
- case 1
minutes of 100, burn of 304 (three torches give only 90 minutes, so a fourth is needed for the last 10) - case 2
minutes of 60, burn of 601 (one torch covers the expedition exactly) - case 3
minutes of 0, burn of 450
- reward
- 140 XP
- signature
torchesNeeded
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- exact multiple of burn time
- leftover minutes need one more torch
- zero minutes needs no torches
- one minute still needs a whole torch
- minutes equal to one torch
- one minute past a single torch
- one-minute torches
- torch longer than expedition