📜  河内塔 - Python 代码示例

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

代码示例2
def towerOfHanoi(N , source, destination, auxiliary):
    if N==1:
        print("Move disk 1 from source",source,"to destination",destination)
        return
    towerOfHanoi(N-1, source, auxiliary, destination)
    print("Move disk",N,"from source",source,"to destination",destination)
    towerOfHanoi(N-1, auxiliary, destination, source)
        
# Driver code
N = 3
towerOfHanoi(N,'A','B','C')
# A, C, B are the name of rods