Hypercube solution in Clear category for Hypercube by JimmyCarlos
# 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:
# 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) ,
# 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]
answerFound = True
grid = passed_in_grid
H,W = len(grid),len(grid)
return any(iterate([(R,C)], grid[R][C]) for R in range(H) for C in range(W))
Sept. 28, 2018