yes, I believe I can just make a list of the greatest common factors and then multiply them out to get the number rather than iterating through 2 through n. Still, I'm curious about the performance difference, since all three are running on the same JVM and ultimately are all compiled down to java byte code, you would expect that a similar algorithm would produce similar results across the three.

On 02/03/2013 07:29 AM, Jules wrote:
If your goal is just to make it fast, then you should use a different
 algorithm, e.g.

(defn bump-up "Bump up n by a multiple of x until greater than or
equal to k." [n x k] (if (>= n k) n (recur (+ n x) x k)))

(defn bump-up-fast "Bump up n by a multiple of x until greater than
or equal to k in O(1)." [n x k] <exercise for the reader>)

(defn lcm "Compute the least common multiple of a and b." [a b] (loop
[n a k b] (cond (< n k) (recur (bump-up n a k) k) (> n k) (recur n
(bump-up k b n)) (= n k) n)))

(defn smallest-multiple-of-1-to-n [n] (reduce lcm (range 1 (+ n
1))))

On Sunday, February 3, 2013 3:28:09 AM UTC+1, Alexandros Bantis
wrote:

Hello all. I'm working through the Project Euler problems in Java,
Scala, & Clojure (trying to learn all three?!?). I notice that for
one particular problem, I use--more or less--a similar algorithm for
all three, but the clojure code runs about 20-30 times slower than
the java/scala versions. Does anyone have any idea why this might be?
It strikes me that it might have something to do with every? but I
don't know because I'm a newbie with Clojure.

http://stackoverflow.com/questions/14668272/what-can-i-do-to-speed-up-this-code


<http://stackoverflow.com/questions/14668272/what-can-i-do-to-speed-up-this-code>


thanks,

alex

-- -- You received this message because you are subscribed to the
Google Groups "Clojure" group. To post to this group, send email to
clojure@googlegroups.com Note that posts from new members are
moderated - please be patient with your first post. To unsubscribe
from this group, send email to clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com. For more
options, visit https://groups.google.com/groups/opt_out.



--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to