human
Possibility of moving out of maze | Function to check whether it will stay inside or come out.
marks all the positions that is visited.
Initial starting point.
initial assumption is it comes out.
runs till it is inside or comes out.
if the movement is towards left then we move left . The start variable and mark that position as visited if not visited previously . Else we break out.
It will be inside forever.
If the movement is towards right , then we move right . The start variable and mark that position as visited if not visited previously else we break out.
it will be inside forever.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to possibility of moving out of maze and the other steps required.
 def checkingPossibility ( a , n , s ) :
	mark = [ 0 ] * n
	start = 0
	possible = 1
	while start >= 0 and start < n :
		if s [ start ] == " < " :
			if mark [ start ] == 0 :
				mark [ start ] = 1
				start -= a [ start ]
			else :
				possible = 0
				break
		else :
			if mark [ start ] == 0 :
				mark [ start ] = 1
				start += a [ start ]
			else :
				possible = 0
				break
	if possible == 0 :
		print " it ▁ stays ▁ inside ▁ forever "
	else :
		print " comes ▁ out "
n = 2
s = " > < "
a = [ 1 , 2 ]
checkingPossibility ( a , n , s )