Hi,

On Feb 15, 2:50 pm, Glen Rubin <rubing...@gmail.com> wrote:

>   ;definition of a palindrome
>   (defn palindrome? [s]
>     (= s (apply str (reverse s))))

You might want to call vec on the string and then rseq instead of
reverse. reverse walks the string twice, while rseq just walks the
string once. The vector will use the underlying string as storage.

  (defn palindrome?
    [s]
    (= s (rseq (vec s))))

>   ;list of palindromes for range of numbers
>   (defn palindromes [start end]
>     (def startmod (- start 1))
       ^^^ No. No. No. Use (let [startmod (dec start)] ....)! def is
toplevel only!

>     (filter #(palindrome? (str %)) (range (* end end) (* startmod
> startmod) -1)))

>   ;yields a lazy sequence of all that are divisible by a 3 digit
> number and yield a 3 digit quotient
>   (defn divis-by-3dig [pal]
>     (filter
>      #(if (zero? (mod pal %)) (< 99 (unchecked-divide pal %) 1000))
>      (range 999 99 -1)))
>
>   (defn p1 []
>   (def palindromic-number (first (filter #(seq (divis-by-3dig %))
> (palindromes 100 999))))
>   (def root1 (first (divis-by-3dig palindromic-number)))
>   (def root2 (unchecked-divide palindromic-number root1))
>   (def message (str "the palindromic number is " palindromic-number "
> its roots are " root1" " root2))
>   message)

Again: no nested def's, defn's, or anything else starting with def.
Use let! def is always global so this will not do, what you think it
does (ie. define a local).

  (defn p1
    []
    (let [palindromic-number (first (filter #(seq (divis-by-3dig %))
(palindromes 100 999)))
          root1 (first (divis-by-3dig palindromic-number))
          root2 (unchecked-divide palindromic-number root1)]
      (str "the palindromic number is " palindromic-number " its roots
are " root1 " " root2)))

Hope this helps.

Sincerely
Meikel

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