devitg.89838
2009-08-02, 01:01 AM
Do you ever seen a lisp to know if a number is prime .
From wikipedia
In mathematics, a prime number (or a prime)
is a natural number which has exactly two distinct natural number divisors:
1 and itself. The first twenty-five prime numbers are:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
I find this in COMMON LISP
(if (< 2 num)
(do ((dividend 2 (1+ dividend))
(chk-to (sqrt num)))
((equal (rem num dividend) 0))
(when (<= chk-to dividend)
(return t)))
t)
But I can not figure out how to implement it on LISP
Thanks in advance
From wikipedia
In mathematics, a prime number (or a prime)
is a natural number which has exactly two distinct natural number divisors:
1 and itself. The first twenty-five prime numbers are:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
I find this in COMMON LISP
(if (< 2 num)
(do ((dividend 2 (1+ dividend))
(chk-to (sqrt num)))
((equal (rem num dividend) 0))
(when (<= chk-to dividend)
(return t)))
t)
But I can not figure out how to implement it on LISP
Thanks in advance