Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Problem 150 - Palindromic numbers question
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Peter  
View profile  
 More options Feb 22 2012, 12:48 am
From: Peter <pgp.copp...@gmail.com>
Date: Tue, 21 Feb 2012 21:48:27 -0800 (PST)
Local: Wed, Feb 22 2012 12:48 am
Subject: Re: Problem 150 - Palindromic numbers question
Hi Leif

Tx for the suggestion. Tried Integer/parseInt iso read-string but that
seems to result in a similar behavior.

Peter

On Feb 21, 11:55 pm, Leif <leif.poor...@gmail.com> wrote:

> 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]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.