Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Hypercube solution in Clear category for Hypercube by JimmyCarlos
def iterate(path,letters):
# If the letters collected can't make the desired word then this is a dead end.
if not "hypercube".startswith(letters.lower()): return
# If we have collected enough letters and passed the first test then we have done it.
if len(letters) == 9:
return True
# If we haven't got enough letters - iterate all possible next steps.
R,C = path[-1]
# Find all possible new positions by moving in all directions
newPositions = [ (R-1,C) ,
(R,C-1), (R,C+1) ,
(R+1,C) ]
# Iterative Step - take a step, adding position to path and letter to letters
answerFound = False
for newR,newC in newPositions:
if 0 <= newR < H and 0 <= newC < W and (newR,newC) not in path:
path_new = path[:] + [(newR,newC)]
letters_new = letters + grid[newR][newC]
if iterate(path_new,letters_new):
answerFound = True
break
return answerFound
def hypercube(passed_in_grid):
global H,W,grid
grid = passed_in_grid
H,W = len(grid),len(grid[0])
return any(iterate([(R,C)], grid[R][C]) for R in range(H) for C in range(W))
Sept. 28, 2018