towers-of-hanoi

linear towers of hanoi

I have a question on the linear Towers of Hanoi. I implemented it in C++ but am trying to do the same using the tail recursive or iterative method. I am having trouble with my algorithm. This code snippet shows transferring blocks from the middle tower to the end tower. #include <stdlib.h> #include <stdio.h> using namespace std; //i...

How does this work? Weird Towers of Hanoi Solution

I was lost on the internet when I discovered this unusual, iterative solution to the towers of Hanoi: for (int x=1; x < (1 << nDisks); x++) { FromPole = (x&x-1)%3; ToPole = ((x|x-1)+1)%3; moveDisk(FromPole,ToPole); } This post also has similar Delphi code in one of the answers. However, for the life of me, ...

Tower of hanoi, python -> scheme, shows error. What am I missing ?

The python implementation import sys def move(src, dst, tmp, num): if num == 1: print 'Move from', src, 'to', dst else: move(src, tmp, dst, num-1) move(src, dst, tmp, 1) move(tmp, dst, src, num-1) move('left', 'right', 'middle', int(sys.argv[1])) Gives the right solution for tower of hanoi. But my sch...

Scaling an iterative, bitwise algorithm to solve the Towers of Hanoi using X discs and Y towers

I like the algorithm mentioned in this question: "How does this work? Weird Towers of Hanoi Solution" http://stackoverflow.com/questions/2209860/how-does-this-work-weird-towers-of-hanoi-solution Is there any way to scale that non-recursive solution of Towers of Hanoi to use X disks and Y towers, with towers represented as stacks? ...

How to represent a Towers of Hanoi problem using a graph?

I am not able to figure out how the graphs shown here are constructed? For example, what does this graph represent? "Nodes are distribution of discs", but I will only have one disc of size a. So, what does node aa represent? I know the answer would be simple, but I cannot figure it out at the moment. ...

How does this iterative Tower of Hanoi work? C

Possible Duplicate: How does this work? Weird Towers of Hanoi Solution Hello, while surfing google, i found this interesting solution to Tower Of Hanoi which doesn't even use stack. Can anybody explain me in brief, what is it actually doing? And this solution really acceptable? #include <stdio.h> #include <stdlib.h> int main...

How can I reduce this problem to the Tower of Hanoi (or solve it in the least number of iterations)?

Suppose there are 2n+1 holes and 2 sets of n sticks, one set white and another black. The sticks are initially organized so that the white sticks are left, there is a hole in the middle and the black sticks are right. A stick can move by either: 1) being placed on the hole next to it, if empty 2) jump the neighboring stick iff the neig...

Crockford's hanoi function (from "The Good Parts")

Hi, at the moment I'm reading Douglas Crockford's book, and the towers of hanoi function is a bit over my head. Even with logging stuff to the console I wasn't able to really understand what's going on. Here's the function with my additions: var hanoi = function (disc, src, aux, dst) { console.log(disc); console.log(src, dst); ...