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):
marchesis a list of non-negative integers.marches[i]is the number of miles walked on dayi. The list may be empty.- Return a new list of integers with the same length as
marches. Entryimust be the sum ofmarches[0]throughmarches[i], inclusive. That is the total miles walked by the end of dayi. - If
marchesis empty, return an empty list.
examples
- case 1
marches of [4, 7, 2][4, 11, 13]: the cairns read 4, then 4 + 7, then 4 + 7 + 2 - case 2
marches of [3, 0, 6][3, 3, 9]: a rest day still gets its cairn, carved with the same total as the day before - case 3
marches of [] (the expedition never set out)[]
- reward
- 120 XP
- signature
cairnMiles
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