The number of moves required to solve the Hanoi tower is 2m + 1 . Therefore for a tower of five disks the minimum number of moves required is: 31.
To move n disks, you need 2n-1moves. In this case, 31.
100000000
If there are N discs, the minimum number of moves required is 2N - 1.
The number of moves required to solve the Hanoi tower is 2m + 1 . Therefore for a tower of five disks the minimum number of moves required is: 31.
To move n disks, you need 2n-1moves. In this case, 31.
The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower, and sometimes pluralized) is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod.
2 with an exponent of n minus onen=number of disks
1,048,575 moves and I know because I did the math.
127
100000000
/* tower of hanoi using recursion */ #include<stdio.h> int main(void) { unsigned int nvalue; char snvalue = 'L' , invalue = 'C' , dnvalue = 'R' ; void hanoi(unsigned int , char , char , char); printf(" enter number of disks : "); scanf("%u",&nvalue ); printf("\n\ntower of hanoi problem with %d disks \n ", nvalue )" hanoi(nvalue , snvalue , invalue , dnvalue ); printf("\n"); return 0 ; } void hanoi(unsigned n , char snd1 , char ind1 , char dnd1 ) { if(n!=0) { /* move n-1 disks from starting to intermadiate needles */ hanoi(n-1 , snd1 , dnd1 , ind1 ); /* move disk n from start to destination */ printf("move disk %d from %c to %c\n ", n , snd1 , dnd1); /* move n-1 disks from intermediate to destination needle */ hanoi(n-1 , ind1 , snd1 , dnd1 ); } }
There is a formula for calculating the number of moves. The formula is 2^n-1. This means that to move one disk the number of moves can be calculated as 2^1-1. For two disks the calculation is 2^2-1. Using this formula the answer 1023 can be found
If there are N discs, the minimum number of moves required is 2N - 1.
It would take 264 - 1 seconds or, at one move per second, approx 585 billion years.
It is the "Tower of Hanoi" and it is a puzzle. When you can solve the puzzle you can write the program, when you have learned enough to write simple programs. You do want to be able to write computer programs, don't you?