1.python算法之汉诺塔
2016-03-20 20:30
603 查看
代码如下:
#!/usr/bin/env python # encoding: utf-8 """ @author: 侠之大者kamil @file: 汉诺塔.py @time: 2016/3/20 20:00 """ m = input(">>Please enter a maximum value of the sequence:") m = int(m)+1 def move(a,b,c,n): if n ==1: print("%s ->> %s : %s" %(a[0],b[0],a[-1])) b.append(a.pop()) print(x,y,z) return move(a,c,b,n-1) print("%s ->> %s : %s" %(a[0],b[0],a[-1])) b.append(a.pop()) print(x,y,z) move(c,b,a,n-1) x = ['x'] y = ['y'] z = ['z'] for n in range(1,m)[::-1]: x.append(n) move(x,y,z,m-1) print(x,y,z)
相关文章推荐
- numpy 数组的体会
- 最好的Python简明教程
- python中ORM框架SQLAlchemy
- python快速入门
- python中多线程编程
- Python特殊语法:filter、map、reduce、lambda [转]
- python中多进程编程
- python3设置打开文件的编码
- leetcode之Longest Substring Without Repeating Characters
- Python-序列化
- Python学习笔记-返回函数
- Python 第七篇:异步IO\数据库\队列\缓存
- Python class method
- 12道 Python面试题总结
- Python singleton instantiation
- python学习学习
- python 关键字 break
- Python Design Patterns
- Mac 下Python 连接MySQL及使用
- Python Singleton Summary