Novicesyntax & basics
The Wraith-Lamps of Bellharrow Causeway
The Bellharrow Causeway runs across the black marsh. Wraiths rise there after dusk, and they will not cross a lit lamp. The Lampwardens of Bellharrow pay coin to any adventurer who will keep the causeway's lamp burning from dusk to dawn, and who brings exactly enough flasks of lampsilver to do it.
The rules of the contract:
- Each flask of lampsilver burns for exactly
burnhours. - Every night must be covered from start to finish by whole flasks.
- A flask that is only partly burnt at dawn is thrown away. Leftover lampsilver is never carried into the next night.
- A night lasting
0hours needs no flasks.
Write flasksNeeded(nights, burn).
nightsis a list of night lengths in hours, one entry per night. Each entry is a non-negative number and may be fractional. The list may be empty.burnis a positive number, possibly fractional: the hours one flask burns.
For each night, the number of flasks it needs is the night's length divided by burn, rounded up to the next whole number. A result that is already whole stays as it is.
Return the total number of flasks needed across all the nights, as an integer.
examples
- case 1
nights of 7.5, 4 and 10 hours; each flask burns 2.5 hours9 flasks (3 + 2 + 4: the 4-hour night needs a second flask for its last 1.5 hours) - case 2
nights of 3, 3 and 3 hours; each flask burns 2 hours6 flasks (2 per night: the spare hour left at each dawn is lost, so the nights cannot share flasks) - case 3
no nights at all; each flask burns 3 hours0 flasks
- reward
- 150 XP
- signature
flasksNeeded
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- mixed nights with fractional burn
- no nights
- zero-hour night needs nothing
- leftovers do not carry over
- fractional nights round up
- exactly one flask
- just over one flask
- exact multiples of a fractional burn
- short nights each need a flask