首页 > 编程语言 > 详细

python基本语法2.4

时间:2017-10-19 15:27:11      阅读:235      评论:0      收藏:0      [点我收藏+]
def move(n, source, target, helper):
    if n == 1:
        print(source +  ->  + target)
    else:
        move(n - 1, source, helper, target)
        print(source +  ->  + target)
        move(n - 1, helper, target, source)

move(4, A, B, C)

‘‘‘
A -> C: [2, 3, 4], [], [1]
A -> B: [3, 4], [2], [1]
C -> B: [3, 4], [1, 2]
A -> C: [4], [1, 2], [3]
B -> A: [1, 4], [2], [3]
B -> C: [1, 4], [], [2, 3]
A -> C: [4], [], [1, 2, 3]
A -> B: [], [4], [1, 2, 3]
C -> B: [], [1, 4], [2, 3]
C -> A: [2], [1, 4], [3]
B -> A: [1, 2], [4], [3]
C -> B: [1, 2], [3, 4], []
A -> C: [2], [3, 4], [1]
A -> B: [], [2, 3, 4], [1]
C -> B: [], [1, 2, 3, 4], []
‘‘‘

 

python基本语法2.4

原文:http://www.cnblogs.com/xiaoyingying/p/7692658.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!