Here's an easy one, with just enough complexity to make golfing non-trivial.
Input
- A list of non-negative numbers representing people waiting in line for Thanksgiving dessert. The first (leftmost) number is first in line, and the list can contain repeats (think of each number as a person's first name):
Note: Pie not part of actual input.
(
)
__..---..__
,-=' / | \ `=-.
:--..___________..--; 6 4 3 1 2 3 0
\.,_____________,./
- A non-empty subset of that list, representing a group of colluding friends who will "chat and cut" to skip ahead in line. All colluders will move just behind the friend already closest to the front of the line, but otherwise retain their relative positions. Everyone they skip past will also retain their relative position.
Output
The new list, after a successful (possibly multi-way) chat and cut. For example, in the list above, for a friend group of 0 2 4
, the output would be:
6 4 2 0 3 1 3
If the friend group was 4 3
, the output would be:
6 4 3 3 1 2 0
Notes
This is code golf with standard site rules.
- A single colluder
x
in the colluder list makes everyone in line with that number a colluder. - The list of people waiting may contain repeats.
- The colluder list will not contain repeats.
- The colluder list may not be sorted.
- The colluder list will have between 2 and U items, where U is the number of unique elements in the queuer list.
Test Cases
The format is:
- People in line.
- List of colluders.
- Output.
5 4 3 2 1 0
3 1
5 4 3 1 2 0
1 2 1 3 1 9
1 9
1 1 1 9 2 3
1 2 3 4 5
4 5
1 2 3 4 5
7 6 1 5 2 4 3
4 5 6
7 6 5 4 1 2 3
7 6 1 5 2 4 3
1 2 3
7 6 1 2 3 5 4
7 6 1 5 2 4 3
3 6
7 6 3 1 5 2 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4 5 4
5 4
1 2 3 4 5 4
1 2 3 4 5 4, 5 4 -> 1 2 3 4 5 4
, because it has duplicate colluders on either side of a different colluder. \$\endgroup\$