On Wed, Feb 16, 2011 at 9:15 AM, Andreas Kostler <andreas.koestler.le...@gmail.com> wrote: > Thanks for everyone who commented on my solution for Euler 28 yesterday. > Euler 40 is a bit easier, even more so I'm disappointed with the performance > of my solution:(defn euler-40 [n-max] > > (reduce #(* (Integer/valueOf (str %1)) (Integer/valueOf (str %2))) > (let [r (range (inc n-max))] > (for [n (iterate #(* % 10) 1) :while (< n n-max)] (nth (apply > str r) n))))) > > It takes about 4s to find the solution. > > First of all, I guess the whole Integer/valueOf ceremony doesn't affect > performance but could probably be dealt with in a more idiomatic way. > Other than that, how could I optimise the presented solution. Hints to other > solutions (as long as they're pretty ;)) are also welcome :)
My solution https://github.com/zuber/project-euler/blob/master/src/com/stepniowski/euler_040.clj takes ~800 ms on my computer. It's basically the same, but I believe it minimalizes the number of conversions from int to string. Cheers, -- Marek Stępniowski http://stepniowski.com -- 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