here is piece of code from exam 2012aa q1.
can someone please explain to me:
1) what is the line "for steps in range(2*n) is needed?
2) every time the program checks if the next bit in the matrix equals to REACHABLE. yet, the first time the code will run, there are no 2's in the matrix, so it suppose to return False every time.
if it does, this code won't work most of the time.
so is it wrong? is it suppost to be "EMPTY" instead of REACHABLE, which will cause problems at the second run?…
2EMPTY, FULL, REACHABLE = 0, 1, 2 def reachable2(maze, i, j): maze[0,0] = REACHABLE # by assumption n,n = maze.dim() for steps in range(2*n): for a in range(n): for b in range(n): if maze[a,b] == FULL: continue # not reachable anyway right = b < n-1 and maze[a,b+1] == REACHABLE left = b > 0 and maze[a,b-1] == REACHABLE down = a < n-1 and maze[a+1,b] == REACHABLE up = a > 0 and maze[a-1,b] == REACHABLE if right or left or down or up: maze[a,b] = REACHABLE return maze[i,j] == REACHABLE