9
2
The Challenge
Given either a string (may have newlines), or a two dimensional array, and a positive integer n
, output the position of the platforms n
turns after the
initial position.
U, D, R, L
are platforms.
^, v, >, <
are arrows that change the directions of the platforms.
U, D, R, L
move up, down, right and left, respectively. When an arrow is in front of a platform, it changes the direction.
Affects platform:
R<
D
^
v
U
>L
>L
<
(top arrow will affect top L
, but bottom arrow won't affect top L
)
Won't affect:
<
R
>
L
v
U
D
^
<R
(R
is going right, so <
won't affect the R
)
For example, if this was the string:
>R <
The platform R
would move right until it's nearly touching the arrow:
> R<
After, it would change the direction and start going left:
> R <
(even though now it's going left, the letter won't change.)
There are some cases when the platform won't move, such as
>R<
or
v
U
^
Last example:
v >
D Rv
^U
^ <
After one turn,
v >
U v
D ^ R
^ <
After one turn,
v >
D Uv
^R
^ <
And one more turn:
v >
R v
D ^ U
^ <
You can assume that the platforms, after n
turns, won't overlap, that the platforms won't go out of bounds, and that a platform won't touch an arrow that's pointing to the same direction as the platform.
Test Cases
Input:
">R <", 4
Output:
"> R <"
Input:
">R <", 6
Output:
">R <"
Input:
">R<", 29
Output:
">R<"
Input:
"v
U
^", 5
Output:
"v
U
^"
Input:
"v
D
^", 1
Output:
"v
D
^"
Input:
"v
D
^", 4
Output:
"v
D
^"
Input:
"v >
D Rv
^U
^ < ", 2
Output:
"v >
D Uv
^R
^ <
Input:
">RL<", 3
Output:
">LR<"
Input:
">L R<", 4
Output:
"> RL <"
Input:
"> RR<
>L R <", 6
Ouput:
">RR <
> RL <"
Input:
"R <", 4
Output:
" R <"
Input:
"R <", 6
Ouput:
"R <"
Rules
- This is code-golf, so shortest answer in bytes wins!
- Standard loopholes are disallowed.
3@closevoters: what is unclear about this challenge? – Leaky Nun – 2016-08-02T18:33:12.360
Time to make an esoteric programming language based on this. – DanTheMan – 2016-08-03T01:00:47.047
Also, what happens if a platform goes off of the grid? – Quelklef – 2016-08-04T07:20:46.750
@Quelklef you can assume that the platforms won't go off of the grid after
n
turns. – acrolith – 2016-08-04T15:42:11.993