‹ back to the board

today · Wednesday, October 28

Novicesyntax & basics

The Selkie-Loom of Brindlecove

On the storm-beaten shore of Brindlecove, the Selkie weavers work a great loom of sealskin and driftwood. Each tide-charm they weave is woven from two spools of enchanted thread, and the charm holds only if the strands are laid in strict alternation. The Weavers' Circle offers a bounty of pearls to whoever can work out the laying order for any pair of spools.

Write weaveSpools(left, right).

  • left is a list of strings, the threads on the left spool, in the order they come off it.
  • right is a list of strings, the threads on the right spool, in the order they come off it.
  • Either list may be empty, and the two lists may have different lengths.

Return a new list of strings: the first thread of left, then the first thread of right, then the second of left, then the second of right, and so on, alternating. Once one list has no threads left, append all remaining threads of the other list in their original order. If both lists are empty, return an empty list.

  • list and array basics
  • Novice

examples

  1. case 1left of ["gold", "grey"], right of ["blue", "black"]["gold", "blue", "grey", "black"]
  2. case 2left of ["gold", "grey", "green"], right of ["blue"]["gold", "blue", "grey", "green"]: the right spool runs out, so the rest of the left follows in order
  3. case 3left of [], right of ["red", "rust"]["red", "rust"]
reward
140 XP
signature
weaveSpools
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…
  • equal lengths
  • left longer
  • right longer
  • left empty
  • right empty
  • both empty
  • repeated threads kept
  • single each
The Selkie-Loom of Brindlecove · bitwick