2 Replies - 645 Views - Last Post: 01 October 2014 - 09:44 PM

#1 brandon916   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 07-September 14

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.
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)



Is This A Good Question/Topic? 0
  • +

Replies To: Trouble understanding exactly what is happening

#2 brandon916   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 07-September 14

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
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1