Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
perfect numbers
--ghc 8.0.1 /opt/ghc/8.0.1/lib/ghc-8.0.0.20160127/ divs n = filter (\x -> n `rem` x == 0) [1..n] isPerfect n = (sum . divs) n == n + n per = filter (isPerfect) [1..] showPer1 = map (\n -> (n , divs n)) per isPrime x = all (\k -> x `rem` k /= 0) [2..x-1] getPrimes [] = [] getPrimes (1:xs) = getPrimes xs getPrimes (x:xs) = x:getPrimes (filter (\k -> k `rem` x /= 0) xs) primes = getPrimes [1..] isM p = isPrime (2 ^ p - 1) mPrimes = (map (\p -> 2 ^ p - 1) . filter isM) primes euclidF p = 2^(p-1) * (2^p -1) euclidPer = (map euclidF . filter isM) primes main = do print $ 6 -- print $ take 4 showPer1 -- print $ take 7 euclidPer
run
|
edit
|
history
|
help
0
haskell linked list
Lowest Common Ancestor in a Binary Tree
(Int,Int) -> Bool plot
mapper
(-‿‿-)
folder
project euler 1, haskel
Niet
project euler 9, haskell
Factors of a number, prime numbers