‹ back to the board

Thursday, October 22

Novicesyntax & basics

The Cairn-Road of Torvane Ridge

The Wayfarers' Lodge is mapping the high road over Torvane Ridge, where the passes close without warning and lost parties are found by their cairns. The rule of the ridge is strict. Each evening the expedition raises one cairn and carves into it the total miles walked since setting out that morning on the first day.

The Lodge holds the expedition's march log. It is a list of the miles walked on each day, in order. Before the next party sets out, it needs the number carved on every cairn.

Write cairnMiles(marches):

  • marches is a list of non-negative integers. marches[i] is the number of miles walked on day i. The list may be empty.
  • Return a new list of integers with the same length as marches. Entry i must be the sum of marches[0] through marches[i], inclusive. That is the total miles walked by the end of day i.
  • If marches is empty, return an empty list.
  • list and array basics
  • Novice

examples

  1. case 1marches of [4, 7, 2][4, 11, 13]: the cairns read 4, then 4 + 7, then 4 + 7 + 2
  2. case 2marches of [3, 0, 6][3, 3, 9]: a rest day still gets its cairn, carved with the same total as the day before
  3. case 3marches of [] (the expedition never set out)[]
reward
120 XP
signature
cairnMiles
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…
  • three days of marching
  • empty march log
  • single day
  • rest days in the middle
  • only rest days
  • a long crossing
The Cairn-Road of Torvane Ridge · bitwick