POV-Ray : Newsgroups : povray.off-topic : FizzBuzz : Re: FizzBuzz Server Time
4 Sep 2024 05:20:47 EDT (-0400)
  Re: FizzBuzz  
From: Orchid XP v8
Date: 5 Jul 2010 13:11:55
Message: <4c32125b$1@news.povray.org>
> Darren New <dne### [at] sanrrcom> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.