What exactly is the halting problem?

前端 未结 22 771
时光说笑
时光说笑 2020-11-29 00:01

Whenever people ask about the halting problem as it pertains to programming, people respond with \"If you just add one loop, you\'ve got the halting program and therefore yo

22条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 00:31

    There's an OK proof the Halting Problem on wikipedia.

    To illustrate, exactly, why just applying some technique to loops is insufficient, consider the following program (pseudocode):

    int main()
    {
      //Unbounded length integer
      Number i = 3;
    
      while(true)
      {
        //example: GetUniquePositiveDivisiors(6) = [1, 2, 3], ...(5) = 1, ...(10) = 1, 2, 5, etc.
        Number[] divisiors = GetUniquePositiveDivisiors(i);
        Number sum = 0;
        foreach(Number divisor in divisiors) sum += divisor;
    
        if(sum == i) break;
    
        i+=2;
      }
    }
    

    Can you think of an approach that will return true if this code halts, and false otherwise?

    Think Carefully.

    If by chance you're in serious contention for a Fields medal, imagine some code for these problems in place of the above.

提交回复
热议问题