if anyone is interested, i used reduces instead of reductions.

2012/12/11 Dennis Haupt <d.haup...@gmail.com>

> i just saw my error.... :/
>
>
> Am 11.12.2012 22:22, schrieb Ben Wolfson:
> > nth is called in doing the destructuring for the argument lists in
> > your fns defined in try-find-sequence.
> >
> > On Tue, Dec 11, 2012 at 1:20 PM, Dennis Haupt <d.haup...@gmail.com>
> wrote:
> >> i am trying to solve euler problem 125. when i tested this code:
> >>
> >> (ns euler.Problem125)
> >>
> >> (defn is-palindrome [n]
> >>   (let [s (str n)]
> >>     (= (seq s) (reverse s))))
> >>
> >> (defn to-check []
> >>   (filter is-palindrome (range 1 1000)))
> >>
> >> (defn square-root [n]
> >>   (Math/sqrt n))
> >>
> >> (defn squared [n]
> >>   (* n n))
> >>
> >> (defn try-find-sequence [n]
> >>   (loop [start-at (int (square-root n))]
> >>     (let [combinator (fn [[sum smallest] element] [(+ sum element) (dec
> >> element)])
> >>           reduced (reduce combinator [0 start-at] (range start-at 0 -1))
> >>           pred (fn [[sum smallest]] (> sum n))
> >>           until-match-or-overflow (take-while pred reduced)
> >>           solution-or-not (last until-match-or-overflow)]
> >>       (cond
> >>         (= (first solution-or-not) n) nil
> >>         (= (first solution-or-not) n) (second solution-or-not)
> >>         :else (recur (dec start-at))))))
> >> (println (try-find-sequence 595))
> >>
> >> i get:
> >> Exception in thread "main" java.lang.UnsupportedOperationException: nth
> >> not supported on this type: Long
> >>         at clojure.lang.RT.nthFrom(RT.java:846)
> >>         at clojure.lang.RT.nth(RT.java:796)
> >>         at
> euler.Problem125$try_find_sequence$pred__16.invoke(Problem125.clj:20)
> >>         at clojure.core$take_while$fn__4116.invoke(core.clj:2512)
> >>
> >> but why? i don't call nth on anything!
> >>
> >> --
> >> 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 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