‹ back to the board

Thursday, October 29

Novicesyntax & basics

The Rearguard Turn of Harrowgast Pass

The Harrowgast Pass is too narrow for riders to go two abreast, so the Wardens of the Pass ride it in single file. The riders at the back take the worst of the dust and the ambushes, so each dusk the Warden-Captain sends the last few riders forward to lead the column. Every other rider keeps their place relative to the others. The Wardens' muster-clerk wants a contract-reckoner who can write down the new marching order before the riders move.

Write rearguardTurn(column, k).

  • column is a list of strings. Each string is a rider's name, listed from the head of the column (index 0) to the rear (the last index). The list may be empty.
  • k is an integer with 0 <= k <= len(column). It is the number of riders taken from the rear.

Return a new list of the same names in the new marching order:

1. First, the last k riders of column, in the same order they had in column. 2. Then all the remaining riders, in the same order they had in column.

If k is 0, or k equals the length of column, the returned list is the same as column.

  • slicing and indexing
  • Novice

examples

  1. case 1column of ["Ansel", "Brea", "Corwin", "Dagny", "Edric"], k of 2["Dagny", "Edric", "Ansel", "Brea", "Corwin"]: Dagny and Edric ride forward and keep their order
  2. case 2column of ["Ysolde", "Tamsin", "Holt"], k of 0["Ysolde", "Tamsin", "Holt"]: nobody moves
  3. case 3column of ["Ysolde", "Tamsin", "Holt"], k of 3["Ysolde", "Tamsin", "Holt"]: the whole column moves forward, so the order is unchanged
reward
130 XP
signature
rearguardTurn
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…
  • two riders move forward
  • k of zero leaves column unchanged
  • k equal to length leaves column unchanged
  • empty column
  • single rider
  • only the last rider moves
  • all but the leader move
The Rearguard Turn of Harrowgast Pass · bitwick