Deanza College 1D Maze in A List Python Project
Question Description
Question:
You are in a 1D maze encoded as a list of non-negative numbers. You enter the room on the leftmost number and the rule is you can only move to squares EXACTLY the number of squares away from the square youre standing on (left or right). The exit is the rightmost number, the last number in the list, and is always 0
(and is the only 0
in the list). Heres a list with one hop to the exit: [3, 9, 9, 0]
…you jump from 3
to 0
and youre out!
Write can_exit(i, L)
to return whether you can exit the maze L
from position index i
. (Assume the maze does not have any loops; like [1, 1, 1, 0]
, where your code can get stuck jumping left and right repeatedly and never get out.)
For example: [1, 3, 5, 10, 2, 10, 10, 0]
– can you get out?
1
right-jump to3
,3
right-jump to2
,2
left-jump to5
,5
right-jump to0
. YES you can!- Some mazes you can’t, like
[10, 0]
, so when can you and when can’t you?
Example calls:
>>> <strong>can_exit(0, [3, 9, 9, 0])</strong>True>>> <strong>can_exit(0, [1, 3, 5, 10, 2, 10, 10, 0])</strong>True>>> <strong>can_exit(0, [10, 0])</strong>False
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."