Tx for the suggestion. Tried Integer/parseInt iso read-string but that
seems to result in a similar behavior.
> Hi, Peter.
> This looks very similar to my code, which worked. The only thing that
> comes to mind is that I didn't use `read-string`, and that function
> might cause problems in the restricted environment the site uses to
> run our code. Someone who knows more about Clojail might know if that
> guess is true.
> Maybe modify those parts of `nxtpal` to use a different method of
> converting strings to integers?
> Good luck,
> Leif
> On Feb 20, 11:51 am, Peter <pgp.copp...@gmail.com> wrote:
> > Hello
> > Running the code below in repl returns in less than a second but on
> > the site it gives a timeout. Not sure what I am doing wrong here
> > I am sure there are more elegant solutions for this problem, but for
> > now I would like to stick with what I have and understand what might
> > be wrong with it.
> > All help warmly welcomed.
> > Tx
> > Peter
> > [code]
> > user=> (def __
> > (fn p151 [n]
> > (letfn [
> > (palindromic? [n] (= (seq (str n)) (reverse (str n))))
> > (nxtpal [n]
> > (let [
> > strn (str n)
> > strln (.length strn)
> > firsthalf (subs strn 0 (/ strln 2))
> > middle (subs strn (/ strln 2) (+ (rem strln 2) (/ strln 2)))
> > guess1 (read-string (apply str (concat firsthalf (concat middle
> > (reverse firsthalf)))))
> > ]
> > (if (> guess1 n)
> > guess1
> > (let [
> > nextfirsthalf (str (inc (Integer/parseInt (apply str
> > (concat firsthalf middle)))))
> > guess2 (cond
> > (= (.length nextfirsthalf) (.length
> > firsthalf)) (concat nextfirsthalf (reverse nextfirsthalf))
> > (= 2 (- (.length nextfirsthalf) (.length
> > firsthalf))) (concat (reverse (rest (reverse nextfirsthalf))) (rest
> > (reverse nextfirsthalf)))
> > :else
> > (concat nextfirsthalf (rest (reverse nextfirsthalf)))
> > )
> > ] (read-string (apply str guess2))
> > )
> > )
> > )
> > )
> > (nextpalindrome [n] (if (< n 9) (inc n) (nxtpal n)))
> > ] (if (palindromic? n)
> > (iterate nextpalindrome n)
> > (rest (iterate nextpalindrome n))
> > )
> > )
> > )
> > )
> > #'user/__
> > user=>
> > user=>
> > user=>
> > user=> (= (take 26 (__ 0)) [0 1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77
> > 88 99 101 111 121 131 141 151 161])
> > true
> > user=> (= (take 16 (__ 162)) [171 181 191 202 212 222 232 242 252 262
> > 272 282 292 303 313 323])
> > true
> > user=> (= (take 6 (__ 1234550000)) [1234554321 1234664321 1234774321
> > 1234884321 1234994321 1235005321])
> > true
> > user=> (= (first (__ (* 111111111 111111111))) (* 111111111
> > 111111111))
> > true
> > user=> (= (set (take 199 (__ 0))) (set (map #(first (__ %)) (range 0
> > 10000))))
> > true
> > user=> (= true (apply < (take 6666 (__ 9999999))))
> > true
> > user=> (= (nth (__ 0) 10101) 9102019)
> > true
> > user=>
> > [/code]