I found a better data structure for calculating lucky numbers. The contrib
library data.avl (from MichaĆ Marczyk) has a persistent sorted-set that
supports nth. This runs much faster than my previous attempts.
(require '[clojure.data.avl :as avl])
(defn lucky-avl
([max] (lucky-avl 1 (apply avl/sorted-set (range 1 max 2))))
([i avl]
(let [n (nth avl i nil)]
(if (and n (<= n (count avl)))
(recur (inc i) (reduce (fn [sss m] (disj sss (nth avl m)))
avl
(range (dec n) (count avl) n)))
(sequence avl)))))
(time (count (lucky-avl 1e6)))
"Elapsed time: 2396.158435 msecs"
71918
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.