‹ back to the board

Sunday, September 6

Novicesyntax & basics

The Lamplighter's Evening Round

The lamps along bitwick's high street are refilled each evening, and the lamplighter carries only so much oil. Before setting out she wants a list of which lamps are actually worth climbing to.

You are given fuel, a list of integers giving the oil remaining in each lamp, in order along the street, and need, an integer: the amount a lamp must hold to burn through the night.

Write shortLamps(fuel, need), which returns a list of integers: the 0-based positions of every lamp whose oil is strictly less than need, in increasing order. A lamp holding exactly need is fine and is not included. If no lamp is short, return an empty list.

  • list and array basics
  • Novice

examples

  1. case 1fuel of [4, 1, 7, 0, 3], need of 4[1, 3, 4] - the lamp at position 0 holds exactly 4, which is enough, so it is left out
  2. case 2fuel of [2], need of 2[] - exactly enough counts as enough
  3. case 3fuel of [], need of 5[]
reward
130 XP
signature
shortLamps
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 street
  • empty street
  • all lamps full enough
  • every lamp short
  • single lamp exactly at the mark
  • single lamp one short
  • negative readings count as short
The Lamplighter's Evening Round · bitwick