human
What is a code to maze With N doors and 1 Key and the other steps required given the following:
Maze With N doors and 1 Key | Recursive function to check whether there is a path from the top left cell to the bottom right cell of the maze.
Check whether the current cell is within the maze.
If key is required to move further.
If the key hasn 't been used before.
If current cell is the destination.
Either go down or right.
Key has been used before.
If current cell is the destination.
Either go down or right.
Driver code.
If there is a path from the cell ( 0 , 0 )"
How can the above be solved in Python?
assistant
#Here is code to maze With N doors and 1 Key and the other steps required.
 def findPath ( maze , xpos , ypos , key ) :
	if xpos < 0 or xpos >= len ( maze ) or ypos < 0 or ypos >= len ( maze ) :
		return False
	if maze [ xpos ] [ ypos ] == '1' :
		if key == True :
			if xpos == len ( maze ) - 1 and ypos == len ( maze ) - 1 :
				return True
			return findPath ( maze , xpos + 1 , ypos , False ) or findPath ( maze , xpos , ypos + 1 , False )
		return False
	if xpos == len ( maze ) - 1 and ypos == len ( maze ) - 1 :
		return True
	return findPath ( maze , xpos + 1 , ypos , key ) or findPath ( maze , xpos , ypos + 1 , key )
def mazeProb ( maze , xpos , ypos ) :
	key = True
	if findPath ( maze , xpos , ypos , key ) :
		return True
	return False
if __name__ == " _ _ main _ _ " :
	maze = [ [ '0' , '0' , '1' ] , [ '1' , '0' , '1' ] , [ '1' , '1' , '0' ] ]
	n = len ( maze )
	if mazeProb ( maze , 0 , 0 ) :
		print ( " Yes " )
	else :
		print ( " No " )