Yet another Brain Tickler

This is a discussion on Yet another Brain Tickler within the C Programming forums, part of the General Programming Boards category; This one is much more challenging Write an iterative procedure for tower of hanoi problem....

  1. #1
    Unregistered
    Guest

    Cool Yet another Brain Tickler

    This one is much more challenging

    Write an iterative procedure for tower of hanoi problem.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Yet another Brain Tickler

    Originally posted by Unregistered
    This one is much more challenging

    Write an iterative procedure for tower of hanoi problem.
    Here's an even more difficult task! USE A SEARCH ENGINE and find the answer yourself. No one is going to do your ****ing homework for you.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    It is showoff time. Actually this is no trouble for me, I have all of this stuff from when I did it. Here it is, but it has 3 things you have to figure out ....

    Code:
    int main(void)
    {   
        Move(DISKS,1,3,2);
         return 1;
    }
    
    void Move(int count, int start, int finish, int temp) {
    
      int swap;
      while (count > 0) {
        Move(count - 1, start, temp, finish);
       // printf("Move disk %d from %d to %d.\n", count, start, finish);
        count--;
        swap = ???;
        start = ???;
        temp = ???;
      }
    }

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by stautze
    It is showoff time. Actually this is no trouble for me, I have all of this stuff from when I did it. Here it is, but it has 3 things you have to figure out ....

    Code:
    void Move(int count, int start, int finish, int temp) {
    
      int swap;
      while (count > 0) {
        Move(count - 1, start, temp, finish);
       // printf("Move disk %d from %d to %d.\n", count, start, finish);
        count--;
        swap = ???;
        start = ???;
        temp = ???;
      }
    }
    You realize that this is a recursive function, right?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I sure hope so.

  6. #6
    Unregistered
    Guest
    I like how you call your assignment a brain tickler. You should be in marketing!

  7. #7
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    >You realize that this is a recursive function, right?

    That is technically true, but I think this is still the answer that he is looking for. A truely iterative version is much less elegant and way to bulky.

    This is a very clever version that eleminates tail recursion by rearanging the termination condition and repeating the the function with a while statement. I would call it iterative, and your compiler would probably agree with me.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Sure, but I doubt they want any recursion. Anyway, there are a million hits on Google for Hanoi Towers, so this really is NEVER needed here again.

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >That is technically true, but I think this is still the answer that he
    >is looking for.

    I don't think so, he said "Write an iterative procedure".

    >A truely iterative version is much less elegant and way to bulky.

    That's true, but that was not his homework. Though if he understands recursion, he can use your function by removing the recursion from it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mouse to have human brain
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 03-10-2005, 04:39 PM
  2. brain vs. computer (brain wins hands down)
    By hk_mp5kpdw in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 09-17-2003, 08:41 PM
  3. Re: Girlfriend Post
    By PsychoBrat in forum A Brief History of Cprogramming.com
    Replies: 57
    Last Post: 05-13-2002, 06:11 AM
  4. Yet another brain tickler
    By golfinguy4 in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-26-2002, 11:23 PM
  5. Brain Tickler
    By Unregistered in forum C Programming
    Replies: 18
    Last Post: 04-25-2002, 03:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21