‹ back to the board

Wednesday, November 11

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 burn hours.
  • 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 0 hours needs no flasks.

Write flasksNeeded(nights, burn).

  • nights is 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.
  • burn is 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.

  • numeric conversion and rounding
  • Novice

examples

  1. case 1nights 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)
  2. case 2nights 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)
  3. case 3no nights at all; each flask burns 3 hours0 flasks
reward
150 XP
signature
flasksNeeded
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…
  • 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
The Wraith-Lamps of Bellharrow Causeway · bitwick