tower of hanoi problem and problem solving
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: tower of hanoi problem and problem solving

  1. #1
    Join Date
    Feb 2012
    Posts
    13

    Question tower of hanoi problem and problem solving

    So i am able to code it, but only because i saw some sample code. the thing with this problem is that you don't expect that you would only need 2 recursive statements to solve it.

    http://www.sparknotes.com/cs/recursi...section6.rhtml


    Use the one disc solution to move the top disc to the intermediate pole.
    Use the one disc solution to move the bottom disc to the final pole.
    Use the one disc solution to move the top disc to the final pole.


    Use the two disc solution to move the top discs to the intermediate pole.
    Use the one disc solution to move the bottom disc to the final pole.
    Use the two disc solution to move the top discs to the final pole.

    Use the N - 1 disc solution to move the top discs to the intermediate pole.
    Use the one disc solution to move the bottom disc to the final pole.
    Use the N - 1 disc solution to move the top discs to the final pole

    However, I think I could have done it if I read these 9 sentences without looking at the code, but only after a few tries. It's very difficult to simulate the whole thing in your head and even now I just have the gist of it and not the whole process in every minute detail. I can parse it, but I feel quite down, because I don't think I could have figured it on my own.

    So I would like to know if most people are like me, or I am just really dumb. This problem is different from a simple for loop, which is easy to simulate in your head, so that was the big wall for me, so to speak. I can program it, but I feel like it's only because I remember the code and not because I fully understood it. I am wondering at what level most programmers understand the algorithm.

  2. #2
    Join Date
    Feb 2012
    Posts
    13

    Re: tower of hanoi problem and problem solving

    move(3,1,3)^ move flow #4 >>final #1 -
    |move(2,1,2)^ move flow #2 s>i >>temp - 2 fin
    ||move(1,1,3)^ move flow #1 s>i >>outoftheway out2 - 1 int
    |||move(0,1,2)
    |||move(0,2,3)
    ||move(1,3,2)^ move flow #3 i>e >>outoftheway in3 - 3 fin (3; 1,2; 0)
    |||move(0,3,1)
    |||move(0,1,2)
    MID POINT
    |move(2,2,3)^ move flow #6 i>e >>final #2 -2 fin
    ||move(1,2,1)^ move flow #5 s>i >>outoftheway out2 -1 int
    |||move(0,2,3)
    |||move(0,3,1)
    ||move(1,1,3) ^ move flow #7 i>e >>final #3 -3 fin (0; 0; 1,2,3)
    |||move(0,1,2)
    |||move(0,2,3)

    i>e final or ootw in

    s>i temp or ootw out


    1 Use the two disc solution to move the top discs to the intermediate pole.
    2 Use the one disc solution to move the bottom disc to the final pole.
    3 Use the two disc solution to move the top discs to the final pole.


    move(3,1,3) START 1 INT 2 END 3
    |move(2,1,2) START 1 INT 3 END 2
    ||move(1,1,3) START 1 INT 2 END 3
    |||move(0,1,2)
    |||move(0,2,3)
    ||move(1,3,2) START 3 INT 1 END 3
    |||move(0,3,1)
    |||move(0,1,2)
    MID POINT
    |move(2,2,3) START 2 INT 1 END 3
    ||move(1,2,1) START 1 INT 2 END 3
    |||move(0,2,3)
    |||move(0,3,1)
    ||move(1,1,3) START 1 INT 2 END 3
    |||move(0,1,2)
    |||move(0,2,3)

    some of the parsing I did, didn't really help at all. I just understand the gist of it.

  3. #3
    Join Date
    Feb 2012
    Posts
    13

    Re: tower of hanoi problem and problem solving

    Also... umm like with the for loop you can know exactly what will happen say at n = 2,

    but for the hanoi tower algorithm, you can't simply know what will happen at say... n = 4 after the 4th recursive call of the first recursive statement.

  4. #4
    Join Date
    Sep 2013
    Posts
    13

    Re: tower of hanoi problem and problem solving

    Quote Originally Posted by wholegrain View Post
    So I would like to know if most people are like me, or I am just really dumb.
    I also find Towers of Hanoi difficult. I've read different explanations in several textbooks and watched lectures on Youtube but I'm still not convinced the inductive proof is correct. In fact I'm pretty sure it isn't!

    Normally I have no problems with recursive algorithms & data structures. I find them quite easy actually. But Towers of Hanoi eludes me and always has. If this means I'm dumb so be it. I've come to accept my shortcoming and it has never stood in my way. I suggest you just drop it and move on.

  5. #5
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,575

    Re: tower of hanoi problem and problem solving

    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center