Piet is an interesting programming language for a number of reasons. Today we will focus on one reason: the roll command. The roll command was originally from PostScript and is a powerful way to manipulate the stack.
The roll command pops the top two elements of the stack and uses them as parameters. We'll call the first value popped
turns and the second
depth. A turn to depth n will take the topmost element of the stack, make it the nth element in the stack, and move each of the elements above it up one. If
turns is negative this is done in the opposite direction. That is, the nth element is moved to the top and the other elements are moved down. This is repeated
Write a program or function that takes in a stack and returns that stack after executing a roll.
- Input and output may be in a list, array, string with a delimiter, passed in one element at a time, or any other reasonable format. Output must be in the same format as the input.
depthwill never be negative and will never be greater than the length of the stack.
- The input stack will always contain at least two elements.
- This is code-golf so the shortest answer in each language wins. As such, I will not be accepting an answer.
- Standard loopholes are forbidden.
in: out: 2 4 1 3 2 4 3 1 4 2 5 5 6 6 in: out: -2 3 1 2 2 3 3 1 in: out: -42 0 1 1 2 2 3 3 4 4 5 5