Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Can You Pass? by UFO665
def can_pass(matrix, first, second):
xMax, yMax = len(matrix) - 1, len(matrix[0]) - 1
curPos = first
x, y = first
val = matrix[x][y]
lstPassed = [curPos]
while curPos != second:
x, y = curPos
lstPos = [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)]
if second in lstPos:
return True
for curX, curY in lstPos:
if (curX, curY) not in lstPassed and 0 <= curX <= xMax and 0 <= curY <= yMax and matrix[curX][curY] == val:
curPos = (curX, curY)
lstPassed.append(curPos)
break
else:
return False
return True
Feb. 14, 2016