2018-03-13 20:40:56 +00:00
|
|
|
# Return an array of primes. This is a trivial and extremely naive algorithm.
|
|
|
|
|
|
|
|
(defn primes
|
|
|
|
"Returns a list of prime numbers less than n."
|
|
|
|
[n]
|
2018-03-24 16:48:42 +00:00
|
|
|
(def list @[])
|
2018-05-24 02:08:36 +00:00
|
|
|
(loop [i :range [2 n]]
|
2018-03-13 20:40:56 +00:00
|
|
|
(var isprime? true)
|
|
|
|
(def len (length list))
|
2018-05-24 02:08:36 +00:00
|
|
|
(loop [j :range [0 len]]
|
2018-03-13 20:40:56 +00:00
|
|
|
(def trial (get list j))
|
2018-03-24 16:48:42 +00:00
|
|
|
(if (zero? (% i trial)) (:= isprime? false)))
|
2018-05-08 23:40:28 +00:00
|
|
|
(if isprime? (array.push list i)))
|
2018-03-13 20:40:56 +00:00
|
|
|
list)
|