Hi Marek,

I think the (inc) in (decimal-fraction-digits) and the (dec) in
(solution) cancel each other out, so the two functions can be
simplified a bit to:

(defn decimal-fraction-digits []
  "Returns the lazy sequence of digits in irrational fraction created
   by concatenating the positive integers"
  (mapcat digits (range)))

(defn solution []
  (reduce * (take 7 (map #(nth (decimal-fraction-digits) %) (iterate
#(* 10 %) 1)))))

On Feb 16, 7:17 am, Marek Stępniowski <mstepniow...@gmail.com> wrote:
> 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 
> solutionhttps://github.com/zuber/project-euler/blob/master/src/com/stepniowsk...
> 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ępniowskihttp://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

Reply via email to