Introduction
You have to simulate playing golf over an input string that represents the green. The 2-character substring ()
represents the hole, and is guaranteed to appear only once in the string.
This is a sample green:
ABCDEFGHIJKLM()NOPQRSTUVWXYZ
The simulation consists of outputting the characters that the ball falls on after a series of hits that are also passed to your function.
Each hit is represented by a positive integer indicating how many characters the ball will travel, relative to previous position.
Example
The following input results in the output G(o)
.
7,7,ABCDEFGHIJKLM()NOPQRSTUVWXYZ
Explanation
The input represents two hits of length 7. The output is a string of characters, showing the intermediate positions of the ball. The ball starts to the left of the string, and travels 7 characters to the right, landing on the G
. As such, that character is the first part of the output.
Then the ball is hit for the second time, and it lands in the hole. In this case, the hole is output with the ball inside, like this: (o)
.
9,7,1,ABCDEFGHIJKLM()NOPQRSTUVWXYZ
I(o)N
The output represents the characters the ball has landed on in the same order as in the string.
Notes
- The width of the hole is 2. If the ball lands on either parenthesis, the hole is hit.
- The direction of the hit is always towards the hole, so when the ball ends up to the right of the hole, the next hit will cause the ball to move to the left (and vice versa).
- The ball might not reach the hole, in which case the position of the ball after the last hit must be output next to the character (in the direction of the hole) the ball is on at the end of the hits. The hole is still included in the output.
example:
28,26,ABCDEFGHIJKLM()NOPQRSTUVWXYZ B12()Z
First 28 hit lands on Z at the right of the hole , next 26 hit is as always thowards the hole (left) and lands on B. No more hits left so the distance to the hole (12 characters) is shown next to B
- If the hits cause the ball to leave the green at some point, discard all remaining hits, and prepend
^
if the ball exits the green to the left, and append$
if the ball leaves the green via the right side. - There might be hits after the putt, in which case those should be discarded, and the hole in the output should not contain an
o
, but anX
.
Test cases
15,10,3,TOURING()MACHINE
I(o)N
7,HOLEIN()NE
(o)
9,7,1,ABCDEFGHIJKLM()NOPQRSTUVWXYZ
I(o)N
7,7,ABCDEFGHIJKLM()NOPQRSTUVWXYZ
G(o)
28,26,ABCDEFGHIJKLM()NOPQRSTUVWXYZ
B12()Z
2,25,26,27,ABCDEFGHIJKLM()NOPQRSTUVWXYZ
AB()Y13Z
1,1,6,SH()RT
SH()$
2,4,6,TOO()HARD
^O()H
4,8,1,3,3,3,3,3,TAKEIT()ASITCOMES
E(X)IT
You have to write a program or function wich accepts a series of positive numbres representing the hits and a [A..Z] string with one hole "()" representig the green. Make clear if your input format is different form 7,7,ABCDEFGHIJKLM()NOPQRSTUVWXYZ
This is code golf, so the submission with the smallest amount of bytes per language wins!