Skip to content

Instantly share code, notes, and snippets.

Created April 29, 2011 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/948680 to your computer and use it in GitHub Desktop.
Save anonymous/948680 to your computer and use it in GitHub Desktop.
;; jneira's solution to http://4clojure.com/problem/67
(fn primes3 [n]
(let
[next-prime
(fn [prs]
(letfn
[(aux [[f & r :as c] nxt]
(println c nxt)
(cond
(empty? c) (conj prs nxt)
(zero? (mod nxt f)) (recur prs (inc nxt))
:else (recur (take-while #(< % (quot nxt f)) r)
nxt)))]
(aux prs (inc (last prs)))))]
(->> (iterate next-prime [2])
(take n)
(last))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment