python - Clojure prime numbers lazy sequence -
What's the closing equivalent of the following Python code (Exact Algorithm)? Calculation import from mathematics by import number sqrt def prime_gen (): primes = [] in count (2) n: if all (in p% p pimes for p & lt; = Sqrt (n)): primes.append (n) yield n
This Python As is as I can:
(def prime-gene (let [prime] (atom []) (for [n (iterized inc 2): when (no-none ? # (Zero? (Rim N%)) (filter # (& lt; =% (math / sqrt n)) @primes) ((swap; primes conj n) n)))) (take 10 prime joints) ; = & Gt; (2 3 5 7 11 13 17 19 23 29)
Close the Closer The number 0 is not considered a boolean false. It took me a few minutes to find out that your Python code is taking advantage of it.
There are some other major number algorithms in the closures. clojure There is also a major number of implementation in contrib.lazy-seqs
.
Comments
Post a Comment