Images, snippets, snapshots, math

View Gabriele Lami's profile on LinkedIn

martedì 8 dicembre 2009

Prime Numbers in haskell

well, do you want to know how to find 'prime numbers' in a quick and dirty
way using Haskell ?
try this!

import Data.List
nubBy ( \x y -> mod y x == 0 ) [2..]

Haskell is so easy and charming...

( ps: if you want to speed up a little bit:
nubBy ( \x y -> ( x*x-1 <= y ) && ( mod y x == 0 ) ) [2..]

)

1 commento:

koteth ha detto...

even better:

nubBy(((.).(.))(0==) (flip $ mod)) [2..]