DEV Community

Cover image for Trying to solve tower of hanoi puzzle to speed up the day of judgement with c++
Rama Reksotinoyo
Rama Reksotinoyo

Posted on • Edited on

Trying to solve tower of hanoi puzzle to speed up the day of judgement with c++

I have ever heard about Indian Tample a.k.a Hanoi tower, containing a big space with 3 towers surrounded by 64 disc, lets imagine the disc like a donuts. Stacked. The diameters of each tower is stacked from smallest at the top the until the biggest at the bottom. According to the some grass-root legend, if there’s the puzzle has been solved the doomday will come quickly as fast as you dont think. The brahma trying to solve this problem to move the disc from first tower to third tower, but the disk must passed the second tower as a temporary temporary.

A few rules to be followed are :

  1. The disk only can be move one-by-one
  2. The larger disk cant be stacked over the smaller disk

So, this problem estimated can be solve so long until the end of the world.
Lets trying to solve this problem *or trying to speed up the end of the world? :D
Mathematically, we neet 2^64-I movement. If there’s any wrong move, the move automatically increased.
Lets try !

void math_problem(int number){
    std::cout<<"Unsolved math problem"<<std::endl;
    int temp;
    if(number % 2==0){
        temp=number/2; 
    }
    else{
        temp=(number*3)+1;
    }
    std::cout<<temp<<std::endl;
}
Enter fullscreen mode Exit fullscreen mode

Ok, lets try this function in main function

int main(){
    hanoi(5,'A','B','C');
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Image description

I passed parameters n with 5, just because if i passed parameters n with 64, there will be 1.8446744e+19 moves and it will definitely take a very long time while running the program.

Maybe you passed the incorrect grammar or tenses, i'm sorry, i'm bad in english :)

Top comments (0)