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).
columnis 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.kis an integer with0 <= 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.
examples
- case 1
column of ["Ansel", "Brea", "Corwin", "Dagny", "Edric"], k of 2["Dagny", "Edric", "Ansel", "Brea", "Corwin"]: Dagny and Edric ride forward and keep their order - case 2
column of ["Ysolde", "Tamsin", "Holt"], k of 0["Ysolde", "Tamsin", "Holt"]: nobody moves - case 3
column 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
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- 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