|
 |
> Darren New <dne### [at] san rr com> writes:
>> I usually ask them to print out the prime numbers less than 100 or something.
>
> 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, 91, 97]
> for prime in prime:
> print prime
primes = f [2..] where f (p:xs) = p : [ x | x <- xs, x `mod` p > 0]
print (take 100 primes)
It's pretty much a standard incantation that most Haskellers will know
off the top of their heads. Of course, it's horrifyingly inefficient for
generating large numbers of primes, but for just the first 100...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |