hanoi.py 296 字节
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
def hanoi(n, a, b, c):
    if n == 1:
        print(a, ' -> ', c)
    else:
        hanoi(n - 1, a, c, b)
        hanoi(1, a, b, c)
        hanoi(n - 1, b, a, c)


if __name__ == '__main__':
    levels = int(input("dash count:"))
    hanoi(levels, 'A', 'B', 'C')
    print(2**levels-1, " times")