# Thread: Yet another Brain Tickler

1. ## Yet another Brain Tickler

This one is much more challenging

Write an iterative procedure for tower of hanoi problem.

2. ## 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.

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

5. I sure hope so.

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

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

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