DEV Community

Cover image for Got the definition of insanity by trying to solve an unsolved math problem with c++
Rama Reksotinoyo
Rama Reksotinoyo

Posted on • Edited on

Got the definition of insanity by trying to solve an unsolved math problem with c++

Past days ago, I have read about unsolved math problem on quantamagazine post. This problem can be easily understood by the mathematicians or not.

Here is the problem :

Choose an integer, if it’s an even number cut it in half. If it’s odd number, multiply the number with three and add 1. Take the calculated number and repeat the process, then you will be stuck in the same loop.

Image description

For the example, I’ll pick 6, it’s even number, definitely.

Image description

I'm stuck in a 4-2-1 loop. But what about the other numbers? Will I still be stuck with the same number?

I tried to prove it with the program.

#include<iostream>

void math_problem(int number){
    int temp=1;
    while(number>0){
        if(number % 2==0){
            number=number/2; 
            std::cout<<number<<std::endl;
        }
        else{
            number=(number*3)+1;
            std::cout<<number<<std::endl;
        }
    }
}

int main(){
    math_problem(29);
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

As a result I am still stuck in the same loop.

Image description

This is like a quote from Albert Einstein, one of the greatest physicists in human history, about the definition of insanity is doing the same thing over and over again, but producing the same result.

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

Top comments (0)