Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Union - find solution in Creative category for Can You Pass? by ale1ster
def can_pass(m, source, target):
rows, cols = len(m), len(m[0])
def neighbours(i, j):
return {(x, y) for (x, y) in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]
if 0 <= x < rows and 0 <= y < cols and m[x][y] == m[i][j]}
cc, last = set(), {source}
while last:
last.update(*map(lambda c: neighbours(*c), last))
last = last - cc
cc |= last
return target in cc
Aug. 27, 2014
Comments: