def towers_of_hanoi(n, start, end):
"""Print the moves required to solve the towers of hanoi game, starting
with n disks on the start pole and finishing on the end pole.
The game is to assumed to have 3 poles.
>>> towers_of_hanoi(1, 1, 3)
Move the top disk from rod 1 to rod 3
>>> towers_of_hanoi(2, 1, 3)
Move the top disk from rod 1 to rod 2
Move the top disk from rod 1 to rod 3
Move the top disk from rod 2 to rod 3
>>> towers_of_hanoi(3, 1, 3)
Move the top disk from rod 1 to rod 3
Move the top disk from rod 1 to rod 2
Move the top disk from rod 3 to rod 2
Move the top disk from rod 1 to rod 3
Move the top disk from rod 2 to rod 1
Move the top disk from rod 2 to rod 3
Move the top disk from rod 1 to rod 3
"""
assert 0 < start <= 3 and 0 < end <= 3 and start != end, "Bad start/end"
"*** YOUR CODE HERE ***"
if n==1:
print("Move the top disk from rod", start, "to rod", end)
else:
towers_of_hanoi(n-1, start, 6-end-start)
towers_of_hanoi(1, start, end)
towers_of_hanoi(n-1, 6-start-end, end)
Trouble understanding exactly what is happening
Page 1 of 12 Replies - 645 Views - Last Post: 01 October 2014 - 09:44 PM
#1
Trouble understanding exactly what is happening
Posted 01 October 2014 - 09:08 PM
So this code is working and all but I do not understand exactly what is going when I use it. Would gladly appreciate an explanation of how this code is working.
Replies To: Trouble understanding exactly what is happening
#2
Re: Trouble understanding exactly what is happening
Posted 01 October 2014 - 09:18 PM
aw shit. Can a mod please move this python section? sorry
#3
Re: Trouble understanding exactly what is happening
Posted 01 October 2014 - 09:44 PM
Please do not duplicate post. In the future, you can click the Report button and it will notify the moderation team.
Page 1 of 1

New Topic/Question
This topic is locked


MultiQuote





|