---------------------------------------------------------------- perfect.lhs -- a halting problem in haskell ---------------------------------------------------------------- Perfect number equals the sum of its proper divisors. Numbers 6, 28, 496, 8128, 33550336... are perfect, but it is not known if there are any odd perfect numbers. ---------------------------------------------------------------- So does oddPerfect halt or not halt? ---------------------------------------------------------------- Find the smallest odd perfect number ---------------------------------------------------------------- > oddPerfect :: Integer > oddPerfect = findIt 1 > where > findIt x > | perfect x = x > | otherwise = findIt (x+2) ---------------------------------------------------------------- Check for a perfect number ---------------------------------------------------------------- > perfect :: Integer -> Bool > perfect x > | x < 2 = False > | otherwise = sum (properDivisors 1 x) == x > where > properDivisors :: Integer -> Integer -> [Integer] > properDivisors n x > | n > x `div` 2 = [] > | x `mod` n == 0 = n:(properDivisors (n+1) x) > | otherwise = properDivisors (n+1) x -- end of file perfect.lhs