tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1 @@
perf n = n == sum [i | i <- [1..n-1], n `mod` i == 0]

View file

@ -0,0 +1,15 @@
perfect = map (\x -> (2^x - 1) * (2^(x - 1))) $
filter (\x -> isPrime x && isPrime (2^x - 1)) maybe_prime where
maybe_prime = scanl1 (+) (2:1:cycle [2,2,4,2,4,2,4,6])
isPrime n = all ((/=0).(n`mod`)) $
takeWhile (\x -> x*x <= n) maybe_prime
isPerfect n = f n perfect where
f n (p:ps) = case compare n p of
EQ -> True
LT -> False
GT -> f n ps
main = do
mapM_ print $ take 10 perfect
mapM_ print $ map (\x -> (x, isPerfect x)) [6,27,28,29,496,8128,8129]