Discuss / Python / 抄作业2019.2.13 表示这个算法弄得脑阔疼

抄作业2019.2.13 表示这个算法弄得脑阔疼

Topic source
# -*- coding: utf-8 -*-
def move(n, a, b, c):
    if n > 1:
        move(n-1,a,c,b)
        move(1,a,b,c)
        move(n-1,b,a,c)
    if n == 1:
        print(a, '-->', c)
move(3, 'A', 'B', 'C')

结果

A --> C
A --> B
C --> B
A --> C
B --> A
B --> C
A --> C

  • 1

Reply