Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
itertools solution in Clear category for Can You Pass? by gyahun_dash
from itertools import chain, product, starmap
def can_pass(matrix, first, second):
digit = matrix[first[0]][first[1]]
cells = product(range(len(matrix)), range(len(matrix[0])))
living = {(y, x) for y, x in cells if matrix[y][x] == digit}
neighbors = lambda y, x: ((y - 1, x), (y + 1, x), (y, x - 1), (y, x + 1))
tips = {first}
while tips:
tips = set(chain.from_iterable(starmap(neighbors, tips))) & living
living -= tips
if second in tips: return True
return False
Aug. 29, 2014
Comments: