18
1
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 abs(turns)
times.
Challenge
Write a program or function that takes in a stack and returns that stack after executing a roll.
Rules
- 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.
depth
will 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.
Test Cases
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
2shortest answer in each language wins, that's not how [code-golf] works. Shortest answer wins. Period. – mbomb007 – 2017-04-03T21:12:18.090
4
@mbomb007 ___ahem___ what about this
– Christopher – 2017-04-03T23:14:05.0377I was very disappointed that this did in no way involve rick rolling – Christopher – 2017-04-04T00:20:10.683
2@mbomb007 I don't see that in the tag description or in a quick search on meta so I don't think that is the case. – Mike Bufardeci – 2017-04-04T14:25:15.990
1@DownChristopher The OP can specify that he's doing a catalog, but it's not the [code-golf] tag itself that makes it that. Code golf by itself simply means shortest wins. Considering that this isn't a trivial example worth cataloging, I'd recommend just doing shortest answer wins. "Hello, World!" is worth a catalog, but this isn't. – mbomb007 – 2017-04-04T15:54:21.867
2@mbomb007 If you would like me to change it, please provide some sort of argument other than saying "you're wrong and I'm right" over and over. There is precedent for this, which you dismissed, and nowhere does it say that challenges require exactly one winner or that an answer must be accepted. – Mike Bufardeci – 2017-04-04T16:41:51.727
"Questions without an objective primary winning criterion are off-topic, as they make it impossible to indisputably decide which entry should win." The precedent for a catalog is only for questions worth cataloging, as in, the question will receive hundreds of answers. A "hello world" question is such a question. This one isn't. – mbomb007 – 2017-04-04T18:14:20.987
2
@mbomb007 If you think that this answer doesn't have an objective winning criterion just because I said I was not accepting an answer then you should vote to close it. No objections were raised in the sandbox but there could still be issues.
There isn't a strict definition of this "catalog" you keep bringing up and I even recall you taking catalog status away from a question. Since there is no clear definition of a catalog I don't see why this can't be one, even though we both deem it unnecessary.
1Can we use Piet? :P – Feathercrown – 2017-04-04T19:41:26.053
@Feathercrown Yes. Piet, PostScript and other languages with a roll builtin are allowed. – Mike Bufardeci – 2017-04-04T19:50:06.433