def hanoi(n, a, b, c): """ 汉诺塔问题: 1.将n-1个盘子从a移动到c 2.将a剩下的一个盘子从a移动到c 3,将n-1个盘子从b经过a移动到c """ if n > 0: hanoi(n - 1, a, c, b) print("moving from %s to %s" % (a, c)) hanoi(n - 1, b, a, c) hanoi(3, "a", 'b', 'c')
2024-04-02 09:01:04
def hanoi(n, a, b, c): """ 汉诺塔问题: 1.将n-1个盘子从a移动到c 2.将a剩下的一个盘子从a移动到c 3,将n-1个盘子从b经过a移动到c """ if n > 0: hanoi(n - 1, a, c, b) print("moving from %s to %s" % (a, c)) hanoi(n - 1, b, a, c) hanoi(3, "a", 'b', 'c')