everyone, I started working yesterday at the Euler project in Clojure, and I have a problem with one of my solutions that I cannot understand.
I have this function:
(defn find-max-palindrom-in-range [beg end]
(reduce max
(loop [n beg result []]
(if (>= n end)
result
(recur (inc n)
(concat result
(filter
(map
I am trying to run it as follows:
(find-max-palindrom-in-range 100 1000)
and I get this exception:
java.lang.Integer cannot be cast to clojure.lang.IFn
[Thrown class java.lang.ClassCastException]
which, I suppose, means that in some place I'm trying to evaluate Integer as a function. However, I cannot find this place, and what puzzles me even more is that everything works if I simply evaluate it as follows:
(reduce max
(loop [n 100 result []]
(if (>= n 1000)
result
(recur (inc n)
(concat result
(filter
(map
(I just removed the function definition and replaced the parameters with constants)
Thank you in advance for your help and it is a pity that I probably embarrass you with an idiotic mistake on my part. Btw I am using Clojure 1.1 and the newest SLIME from ELPA.
: is-palindrom?. , .
(defn is-palindrom? [n]
(loop [num (String/valueOf n)]
(cond (not (= (first num) (last num))) false
(<= (.length num) 1) true
:else (recur (.substring num 1 (dec (.length num)))))))