Novicesyntax & basics
The Lamplighter's Empty Glass
Every dusk the lamplighter of bitwick walks Kettle Lane, which is lined with lamps in a fixed row. Before she climbs her ladder she writes down how much oil sits in each glass, in order from the first lamp to the last. A lamp with no oil at all is a dark lamp, and she carries only enough oil for those.
You are given fuel, a list of non-negative integers: the oil in each lamp, in row order.
Write darkLamps(fuel), which returns a list of integers — the 0-based positions of every lamp whose oil is exactly 0, listed from smallest position to largest. If no lamp is dark, return an empty list.
examples
- case 1
fuel of [3, 0, 5, 0, 0][1, 3, 4] — the second, fourth and fifth lamps are dark - case 2
fuel of [7, 7][] — every lamp has oil, so the list comes back empty - case 3
fuel of [0][0] — the only lamp is dark, and its position is 0
- reward
- 120 XP
- signature
darkLamps
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- several dark lamps
- all lamps full
- single dark lamp
- empty lane
- every lamp dark
- dark lamp at each end