Difference between revisions of "Haskell Quiz/Weird Numbers/Solution Dolio"
Jump to navigation
Jump to search
(Naive solution) |
(No difference)
|
Revision as of 01:53, 27 October 2006
A first, rather naive solution:
module Main where
import Control.Monad.Reader
import Data.List
import System
power = filterM $ const [True,False]
divisors n = sort $ 1 : join [ [x, n `div` x] | x <- l ]
where l = filter ((==0) . (mod n)) . takeWhile ((<n) . join (*)) $ [2..]
weird n = sum s > n && all (n/=) (map sum ss)
where (s:ss) = power $ divisors n
main = print . filter weird . enumFromThenTo 70 72 . read . head =<< getArgs