Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have never encountered a program so far which I couldn't decide whether it would halt or not. You would completely convince me if you could describe such a program

Does this halt? Assume all variables are arbitrary precision integers.

/* http://en.wikipedia.org/wiki/Perfect_number#Odd_perfect_numb... */

  void searchForOddPerfectNumber() {
    int n = 1, sumOfFactors, factor;

    while (1) {
      sumOfFactors = 0;
      for (factor = 1; factor < n; factor++)
        if (n % factor == 0)
          sumOfFactors += factor;
      if (sumOfFactors == n) break;
      n += 2;
      sumOfFactors = 0;
    }
  }


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: