‹ back to the board

Monday, September 14

Novicesyntax & basics

The Nightwatch Roster

The watch-captain of bitwick keeps the night roster on a slate by the gatehouse door: a line of watcher names in the order they take the wall. When a night passes, the name at the front of the line goes to the very back and every other name moves up one place.

Write nightWatch(names, nights).

  • names is a list of strings, the roster in its current order.
  • nights is an integer, zero or greater, counting how many nights pass.

Return a list of strings: the roster after that many nights have passed.

nights may be larger than the number of names on the slate. If names is empty, return an empty list.

  • slicing and indexing
  • Novice

examples

  1. case 1names of ["Ada", "Bram", "Cora", "Dell"], nights of 1["Bram", "Cora", "Dell", "Ada"]
  2. case 2names of ["Ada", "Bram", "Cora"], nights of 7["Bram", "Cora", "Ada"] — seven nights over three watchers lands in the same place as one night
  3. case 3names of [], nights of 5[] — an empty slate stays empty
reward
130 XP
signature
nightWatch
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…
  • one night shifts by one
  • zero nights leaves the slate alone
  • more nights than watchers
  • a full turn comes back around
  • empty slate
  • lone watcher
  • partway through a long roster
The Nightwatch Roster · bitwick