The Knotted Cord of the Varrow Pathfinders
The Varrow Pathfinders mark their trails on a long cord. Each knot along it stands for one landmark of the route, tied in the order the landmarks are met. A scout running ahead does not read every knot. They read the first knot, then every k-th knot after it, and they keep going until the cord runs out.
The Pathfinders' lodge will pay for a reckoning of what such a scout reads.
Write readKnots(knots, k).
knotsis a list of strings, the landmark names in cord order. It may be empty.kis an integer, at least 1.
Return a new list holding the knots at positions 0, k, 2·k, 3·k, … and so on, counting positions from 0, for every position that exists in knots. Keep them in their original order. If knots is empty, return an empty list.
examples
- case 1
knots of ["Ford", "Oak", "Cairn", "Spring", "Ridge", "Hollow", "Gate"], k of 3["Ford", "Spring", "Gate"] - case 2
knots of ["Ford", "Oak", "Cairn"], k of 10["Ford"]. The first knot is always read, even when the next one would lie past the end of the cord. - case 3
knots of [], k of 2[]
- reward
- 140 XP
- signature
readKnots
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- every second knot
- every third knot
- k of one reads every knot
- k longer than the cord
- empty cord
- single knot
- last knot lands exactly
- repeated landmark names