Ahem.
Here is a more idiomatic version that runs under half a second, no
annotations required.
(def vs (atom {}))
(defn sk [k]
(if (@vs k)
(@vs k)
(let [ans (if (< k 56)
(- (mod (+ 100003 (- (* k 200003)) (* 300007 k k k))
1000000) 500000)
(- (mod (+ (sk (- k 24))
(sk (- k 55))) 1000000)
500000))]
(do (swap! vs assoc k ans)
ans))))
user> (reset! vs {})
{}
user> (time (dorun (map sk (range 100000))))
"Elapsed time: 155.082351 msecs"
nil
I guess the moral is that the built-in data structures are quite fast,
and reflection is evil.
--
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