Re: [q-lang-users] Problem using function "isprime"
Brought to you by:
agraef
From: Tim H. <q...@st...> - 2004-10-09 12:53:10
|
Dr....@t-... (Albert Graef) writes: [snip] > Here's a suitable definition which you can add to your program, copied > straight from the docs: [snip] While we're here, consider this pair of mutually-recursive functions for the job, as well: isprime N = not (any ((=0).(N mod))) (primes (intsqrt N)) ; primes N = [2] if N=2; = filter isprime [2..N] otherwise; Not quite as pretty to look at, but I think it may run faster as it only uses the primes between 2..intsqrt N rather than all odds, if I read your algorithm right... HTH, ~Tim -- <http://spodzone.org.uk/> |