Last active
September 16, 2015 13:32
-
-
Save luochen1990/29086276dd4bed5bb1d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isPrime x = all (\p -> x `mod` p /= 0) . takeWhile ((<= x) . (^ 2)) $ primes | |
primes = 2 : 3 : filter isPrime [5..] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ghci> let (isPrime, primes) = ((\x -> all (\p -> x `mod` p /= 0) . takeWhile((<= x) . (^2)) $ primes), 2 : 3 : filter isPrime [5..]) | |
ghci> take 10 primes | |
[2,3,5,7,11,13,17,19,23,29] | |
ghci> takeWhile (< 100) primes | |
[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment