Answers for "python towers of hanoi recursive"

0

python towers of hanoi recursive

# Python towers of hanoi recursive
def hanoiArray(n):

    def move(n, start=1, end=3):
        if n > 0:
            ans.append(move(n-1, start, 6 - start - end))
            pegs[end-1].append(pegs[start-1].pop())
            move(n-1, 6 - start - end, end)
        return str(pegs)

    ans, pegs = [], [list(range(n, 0, -1)), [], []]
    ans.append(move(n))
    return '\n'.join(ans)
Posted by: Guest on May-12-2021

Python Answers by Framework

Browse Popular Code Answers by Language