4 ms·
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 pr
by bumbledraven 14y ago
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_numbers 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;
}
}