‹ back to the board

Sunday, October 11

Novicesyntax & basics

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).

  • knots is a list of strings, the landmark names in cord order. It may be empty.
  • k is 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.

  • slicing and indexing
  • Novice

examples

  1. case 1knots of ["Ford", "Oak", "Cairn", "Spring", "Ridge", "Hollow", "Gate"], k of 3["Ford", "Spring", "Gate"]
  2. case 2knots 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.
  3. case 3knots of [], k of 2[]
reward
140 XP
signature
readKnots
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…
  • 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
The Knotted Cord of the Varrow Pathfinders · bitwick