Personal tools

Haskell Quiz/Weird Numbers/Solution Dolio

From HaskellWiki

< Haskell Quiz | Weird Numbers
Revision as of 01:53, 27 October 2006 by Dolio (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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