Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- def hanoi(n, origem, ajuda, destino):
- print "hanoi( ", n, origem, ajuda, destino, " e lá vamos nós"
- if n > 0:
- # mova a torre de tamanho n - 1 para ajuda:
- hanoi(n - 1, origem, destino, ajuda)
- # mova o disco do bastão origem para o bastão destino
- if origem[0]:
- disco = origem[0].pop()
- print "movendo o disco " + str(disco) + " da " + origem[1] + " para " + destino[1]
- destino[0].append(disco)
- # mova a torre de tamanho n-1 da ajuda para o destino
- hanoi(n - 1, ajuda, origem, destino)
- origem = ([4,3,2,1], "origem")
- destino = ([], "destino")
- ajuda = ([], "ajuda")
- hanoi(len(origem[0]),origem,ajuda,destino)
- print origem, ajuda, destino
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement