码迷,mamicode.com
首页 > 编程语言 > 详细

python基本语法2.4

时间:2017-10-19 15:53:35      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:[]   else   pre   def   pytho   ==   int   style   bsp   

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

标签:[]   else   pre   def   pytho   ==   int   style   bsp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!