‹ back to the board

Monday, September 7

Novicesyntax & basics

The Night Watch Roster

The inn at bitwick keeps the night watch roster on a slate by the door: the watchers' names, written in the order they take the wall.

Each dawn the slate is rewritten so that a different name stands first, and everyone else follows in the same cyclic order as before. No name is added, dropped, or repeated — only the starting point moves.

Write watchOrder(watch, k).

  • watch is a list of strings, the names in their current order.
  • k is an integer, zero or greater: how many places the start of the roster moves forward.

Return a new list of strings containing exactly the same names, beginning with the name at position k and continuing in order, wrapping back to the front of the list when the end is passed. If k is greater than or equal to the number of names, it continues to wrap around (so a k equal to the length gives back the original order). If watch is empty, return an empty list.

Do not modify the list you were given.

  • slicing and indexing
  • Novice

examples

  1. case 1watch of ["Ada", "Bram", "Cleo", "Dag"], k of 1["Bram", "Cleo", "Dag", "Ada"]
  2. case 2watch of ["Ada", "Bram", "Cleo", "Dag"], k of 6["Cleo", "Dag", "Ada", "Bram"] — 6 wraps twice around the four names
  3. case 3watch of [], k of 3[]
reward
130 XP
signature
watchOrder
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…
  • shifts by one
  • zero leaves the order alone
  • a full turn returns to the start
  • wraps more than once
  • empty slate
  • a lone watcher
  • last name first
The Night Watch Roster · bitwick