Objective
Generate the original scrambled list, from the movements that an Insertion Sort would do to sort it.
The original list will have all numbers from 0
to N-1
(inclusive) where N
is the size of the input.
Input
A list containing the necessary moves to sort the list. Each value represents the amount of slots displaced by the original (scrambled) number to be in his right position , keep in mind that this process is from the left to the right.
The value at (0-indexed) position i
in the input list will be between 0
and i
inclusive.
You don't need to handle invalid inputs, any behaviour is acceptable in this case (crash, infinite loop, etc).
Output
The scrambled list
Step-by-step to generate the moves
Scrambled List | Moves to sort
[4,0,2,1,3,5] | [0, , , , , ] #4 stay in place
[4,0,2,1,3,5] | [0,1, , , , ] #0 is moved 1 slot to the left
[0,4,2,1,3,5] | [0,1,1, , , ] #2 is moved 1 slot
[0,2,4,1,3,5] | [0,1,1,2, , ] #1 is moved 2 slot
[0,1,2,4,3,5] | [0,1,1,2,1, ] #3 is moved 1 slot
[0,1,2,3,4,5] | [0,1,1,2,1,0] #5 is in the right place already
[0,1,2,3,4,5]
So, for the input [0,1,1,2,1,0]
your program need to output [4,0,2,1,3,5]
.
Keep in mind that the movements aren't to the position in the (final) sorted list, but in the sorted segment(the bolded section)
Test Cases
[0,0,0] -> [0,1,2]
[0,1,0,1] -> [1,0,3,2]
[0,0,0,0,0,5] -> [1,2,3,4,5,0]
[0,1,2,3] -> [3,2,1,0]
[0,1,1,1] -> [3,0,1,2]
[0,1,1,2,1,0] -> [4,0,2,1,3,5]
Winning
This is code-golf, so the shortest answer wins.