English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

When I was at school, my Maths teacher showed me a way to decipher the correct moves for the TOH. He wrote out the binary numbers in sequence, and then "read" them. I think it went from right to left? This would show you which moves to make for minimum number. Does anyone know of this technique please?

2006-09-15 20:39:06 · 4 answers · asked by Dr Matt W (Australia) 6 in Science & Mathematics Mathematics

4 answers

Wikipedia has all the answers http://en.wikipedia.org/wiki/Towers_of_hanoi

2006-09-15 20:51:14 · answer #1 · answered by gp4rts 7 · 0 0

The Tower of Hanoi or Towers of Hanoi is a mathematical game or puzzle. It consists of three pegs, and a number of discs of different sizes which can slide onto any peg. The puzzle starts with the discs neatly stacked in order of size on one peg, smallest at the top, thus making a conical shape.

The object of the game is to move the entire stack to another peg, obeying the following rules:

* only one disc may be moved at a time
* no disc may be placed on top of a smaller disc

2006-09-16 10:31:51 · answer #2 · answered by Anonymous · 0 0

It is a beautiful example of "recursive programming", that is a routine that calls itself many times.
If you stay long enough, I'll give you some code in "C".

You have a pile of disks on the left pole (or right if you want!), and you have to move the disks to the OTHER side, using the middle pole as spare.
Depending of the NUMBER of disks, (odd or even), you make your first move to one of the two poles.
If the number is odd, the first move is to the FINAL pole.
If the number is even the first move is to the spare pole.

2006-09-16 05:05:43 · answer #3 · answered by just "JR" 7 · 0 0

//Towers of Hanoi problem(recursive solution)
#include
void towers(int,char,char,char);
main()
{
int n;clrscr();
printf("Enter total no. of disks:\n");
scanf("%d",&n);
towers(n,'A','B','C');
getch();
}

void towers(int n,char from,char aux,char to)
{
if(n==1){
printf("\n%s %s %c %s %c","move disk1","from peg",from,"to peg",to);
return;
}
towers(n-1,from,to,aux);
printf("\n%s %d %s %c %s %c","move disk",n,"from peg",from,"topeg",to);
towers(n-1,aux,from,to);
}


I've done this program using C-code. Hope u've understood it.
aux : AUXILLIARY PEG,
from: FROM peg,
to: TO peg.

2006-09-16 06:46:57 · answer #4 · answered by Innocence Redefined 5 · 0 0

fedest.com, questions and answers