primes/primes.hs

19 lines
414 B
Haskell
Raw Normal View History

2011-03-08 07:01:27 +00:00
-- Haskell version of a Prime Number Finder
-- haplo@mindstab.net
import System.IO
import System.Environment
2011-03-08 07:01:27 +00:00
check i c m | i > m = [(show c) ++ " "]
| rem c i > 0 = check (i+2) c m
| otherwise = []
primes c m s t | c < m && c >= t = primes c m (s+1) ((s+1)*(s+1))
| c < m = check 3 c s ++ primes (c+2) m s t
| otherwise = []
main = do
x <- getArgs
print (primes 3 (read (x!!0)::Int) 2 4)