Skip to content

Instantly share code, notes, and snippets.

@petitviolet
Created September 5, 2015 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petitviolet/48d13968d4e477f1bba4 to your computer and use it in GitHub Desktop.
Save petitviolet/48d13968d4e477f1bba4 to your computer and use it in GitHub Desktop.
素数判定
isPrime :: Integer -> Bool
isPrime n
| n <= 1 = False
isPrime n = not $ elem 0 [n `mod` x | x <- [2..floor $ fromIntegral n ** 0.5]]
primes :: [Integer]
primes = f[2..] where
f(p : ns) = p : f(filter isPrime ns)
-- f(p : ns) = p : f(filter ((/=0) . (`mod` p)) ns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment