# A006780, Miles Conway maxN = 50 maxDim = 2*maxN+1 arraySize = maxDim*maxDim*maxDim visited = [False for i in range(0,arraySize)] def pos(x,y,z) : return (x+maxN)*maxDim*maxDim + (y+maxN)*maxDim + (z+maxN) def newvia(x,y,z,left, laststep): if visited[pos(x,y,z)] : return 0 if left == 0 : return 1 visited[pos(x,y,z)] = True if laststep == '': result = newvia(x+1,y,z,left-1, '') result+= newvia(x-1,y,z,left-1, '') result+= newvia(x,y-1,z,left-1, '') result+= newvia(x,y+1,z,left-1, '') result+= newvia(x,y,z-1,left-1, '-z') result+= newvia(x,y,z+1,left-1, '+z') if laststep == '+z': result= newvia(x,y,z+1,left-1, '+z') result+= newvia(x,y+1,z,left-1, '') if laststep == '-z': result= newvia(x,y,z-1,left-1, '-z') result+= newvia(x,y-1,z,left-1, '') visited[pos(x,y,z)] = False return result n = 0 while True: print(str(newvia(0, 0, 0, n, ''))) n += 1