September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,15 +1,19 @@
|
|||
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
|
||||
perfect =
|
||||
(\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
|
||||
isPerfect n = f n perfect
|
||||
where
|
||||
f n (p:ps) =
|
||||
case compare n p of
|
||||
EQ -> True
|
||||
LT -> False
|
||||
GT -> f n ps
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
mapM_ print $ take 10 perfect
|
||||
mapM_ print $ map (\x -> (x, isPerfect x)) [6,27,28,29,496,8128,8129]
|
||||
mapM_ print $ take 10 perfect
|
||||
mapM_ (print . (\x -> (x, isPerfect x))) [6, 27, 28, 29, 496, 8128, 8129]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue