Task: Using your language of choice, implement a program that will a) Prompt the user for 2 numbers, and b) output the number of prime numbers between the two numbers (inclusive.)
Output: A B N
Name:
Anonymous2008-05-08 21:06
Why do I do these /prog/ challenges? Its like I can't resist a chance to show off my baby, my Haskell. HELP ME!!!
module Main where
import Control.Monad
primes = map head $ iterate seive [2 ..]
where seive (x:xs) = [n | n <- xs, not $ x `divides` n]
a `divides` b = b `mod` a == 0
main :: IO ()
main = do [a, b] <- replicateM 2 $ liftM read $ getLine
let primes' = takeWhile (<b) $ dropWhile (<a) primes
print $ length primes'