Another idea stolen from Ed. This defines a lazy sequence of primes, and holds on to the head, so whichever primes have been realised are memoised, and so are cached for future access.
Takes about 45 seconds to run.
(def primes
(let [known-primes (atom (list))]
(for [n (iterate inc 2)
:when (or
(= 2 n)
(not-any? #(zero? (mod n %)) @known-primes))]
(do
(swap! known-primes conj n)
n))))
(defn solve []
(nth primes 10000))
Org-mode PDF export failure
-
Having replaced my laptop due to a tea related accident, I am finding a few
things that I need to reconfigure. Org exports are one of them. On my new
fedor...
14 years ago
No comments:
Post a Comment