Where will the ball land?
Python, 143B
import sys
for l in sys.stdin:
a=l.find('.')
if a>-1:F=a
elif F>-1:
if'\\/'in l[F-1:F+2]:z
F+={'\\':1,'/':-1}.get((l+' '*F)[F],0)
print F+1
Using the space/tab indentation trick. I haven't done anything particularly clever here. F
is the current index, l
is the current line; z
is undefined so it throws an exception, which is definitely not a positive integer, handling the \/
situation.
05AB1E, 37 bytes
¶¡ð«ć'.ksvU…/ \yXD>‚èJD„\/Qiõqëнk<X+]>
Input as a multi-line string. Outputs \/
if the ball is stuck.
Try it online or verify all test cases.
Explanation:
¶¡ # Split the (implicit) input-string on newlines
# (work-around instead of `|`, because it will stop at empty lines)
ð« # Add a trailing space to each line (work-around because indexing
# -1 in 05AB1E will wrap around to the other side)
ć # Extract head; pop and push the remainder-lines and first line
# separated to the stack
'.k '# Get the 0-based index of "." in this first line
s # Swap to get the remainder-list of lines
v # Loop over each line `y`:
U # Pop and store the top value (the index) in variable `X`
X # Push the current index `X`
D> # Duplicate it, and increase the copy by 1
‚ # Pair to [X, X+1]
y è # Index both of those into the current line `y`
JD # Join the two characters together, and duplicate it
„\/Qi # If it's equal to "\/":
q # Stop the program
# (after which the string is output implicitly as result)
ë # Else:
н # Only leave the first character (at index `X`)
…/ \ k # Get its 0-based index in string "/ \"
< # Decrease it by 1
X+ # And add it to `X`
] # After the loop:
> # Increase the top of the stack (`X`) by 1
# (after which it's output implicitly as result)