‹ back to the board

Tuesday, November 10

Novicesyntax & basics

The Spirit-Totem of Ulgrath Fells

High on Ulgrath Fells, the clans keep a spirit-totem of carved figures. Each new figure is set on top of the last, so the totem grows upward, one carving at a time. Before the winter rite, the Shamans' Circle posts a bounty for a reading of the uppermost figures, spoken from the top down.

Write readTotem(carvings, k).

  • carvings is a list of strings. Each string names one figure, listed from the bottom of the totem (first element) to the top (last element).
  • k is a non-negative integer.

Return a list of strings with the top k figures, ordered from the topmost figure first downward.

  • If k is greater than or equal to the number of figures, return every figure, still topmost first.
  • If k is 0, or carvings is empty, return an empty list.
  • slicing and indexing
  • Novice

examples

  1. case 1carvings of ["Bear", "Elk", "Raven", "Owl"] (bottom to top), k of 2["Owl", "Raven"]
  2. case 2carvings of ["Bear", "Elk", "Raven", "Owl"], k of 6["Owl", "Raven", "Elk", "Bear"] (more asked for than exist, so all four, topmost first)
  3. case 3carvings of ["Bear", "Elk", "Raven", "Owl"], k of 0[] (nothing is read)
reward
140 XP
signature
readTotem
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…
  • top two of four
  • k equals length
  • k exceeds length
  • k is zero
  • empty totem
  • single figure
  • top three of five
  • top one of five
The Spirit-Totem of Ulgrath Fells · bitwick