1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-24 07:20:27 +00:00
janet/examples/primes.janet

15 lines
377 B
Plaintext
Raw Normal View History

# 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]
(def list @[])
(for i 2 n
(var isprime? true)
(def len (length list))
(for j 0 len
(def trial (get list j))
(if (zero? (% i trial)) (set isprime? false)))
(if isprime? (array/push list i)))
list)