📜  python towers of hanoi recursive - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:32.008000             🧑  作者: Mango

代码示例1
# 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)