2018-03-13 20:40:56 +00:00
|
|
|
# Return an array of primes. This is a trivial and extremely naive algorithm.
|
|
|
|
|
|
|
|
(defn primes
|
2018-08-23 01:41:25 +00:00
|
|
|
"Returns a list of prime numbers less than n."
|
|
|
|
[n]
|
|
|
|
(def list @[])
|
2018-11-29 18:30:59 +00:00
|
|
|
(for i 2 n
|
2018-08-23 01:41:25 +00:00
|
|
|
(var isprime? true)
|
|
|
|
(def len (length list))
|
2018-11-29 18:30:59 +00:00
|
|
|
(for j 0 len
|
2018-08-23 01:41:25 +00:00
|
|
|
(def trial (get list j))
|
2018-12-17 02:57:32 +00:00
|
|
|
(if (zero? (% i trial)) (set isprime? false)))
|
2018-12-01 03:49:21 +00:00
|
|
|
(if isprime? (array/push list i)))
|
2018-08-23 01:41:25 +00:00
|
|
|
list)
|