2017-11-25 09:23:50 +00:00
|
|
|
from __future__ import print_function
|
2016-08-14 12:13:32 +00:00
|
|
|
def moveTower(height, fromPole, toPole, withPole):
|
|
|
|
'''
|
|
|
|
>>> moveTower(3, 'A', 'B', 'C')
|
|
|
|
moving disk from A to B
|
|
|
|
moving disk from A to C
|
|
|
|
moving disk from B to C
|
|
|
|
moving disk from A to B
|
|
|
|
moving disk from C to A
|
|
|
|
moving disk from C to B
|
|
|
|
moving disk from A to B
|
|
|
|
'''
|
|
|
|
if height >= 1:
|
|
|
|
moveTower(height-1, fromPole, withPole, toPole)
|
|
|
|
moveDisk(fromPole, toPole)
|
|
|
|
moveTower(height-1, withPole, toPole, fromPole)
|
|
|
|
|
|
|
|
def moveDisk(fp,tp):
|
2017-11-25 09:23:50 +00:00
|
|
|
print(('moving disk from', fp, 'to', tp))
|
2016-08-14 12:13:32 +00:00
|
|
|
|
|
|
|
def main():
|
2018-10-19 08:30:31 +00:00
|
|
|
height = int(raw_input('Height of hanoi: '))
|
2016-08-14 12:13:32 +00:00
|
|
|
moveTower(height, 'A', 'B', 'C')
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|