Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
12-liner: stack it up solution in Clear category for Hypercube by przemyslaw.daniel
def hypercube(data):
height, width, hp = len(data), len(data[0]), 'hypercube'
valid = {(x, y) for x in range(height) for y in range(width)}
stack = [('', x, y) for x, y in valid if data[x][y] in 'Hh']
while stack:
text, x, y = stack.pop()
if text.lower() == hp:
return True
neighbors = {(x+1, y), (x-1, y), (x, y+1), (x, y-1)}
for i, j in list(neighbors & valid)*(len(text) <= len(hp)):
stack += [(text+data[x][y], i, j)]
return False
Sept. 27, 2018