Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

90% of /prog/ cannot write this BASIC PROGRAM

Name: Anonymous 2008-05-08 20:11

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: Anonymous 2008-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'

Name: Anonymous 2008-05-09 5:13

>>10
HELLO VIXEY

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List