I normally use

(defn digits [n]
  (map #(Integer/parseInt (str %))  (seq (str n))))

You can adapt it to read in different bases easily.

sincerely,
--Robert McIntyre


On Thu, Feb 17, 2011 at 9:45 PM, Matthew Boston
<matthew.bos...@gmail.com> wrote:
> How about using the Java api Character/getNumbericValue, like so:
>
> (defn explode-to-digits [number]
>  (map #(Character/getNumericValue %) (str number)))
>
> user => (explode-to-digits 12345)
> (1 2 3 4 5)
>
> On Feb 17, 4:45 pm, Mike Meyer <m...@mired.org> wrote:
>> On Thu, 17 Feb 2011 15:27:47 -0600
>>
>> Michael Gardner <gardne...@gmail.com> wrote:
>> > On Feb 17, 2011, at 1:36 PM, Mike Meyer wrote:
>>
>> > > My turn...
>>
>> > > (defn to-digits
>> > >  "Create a seq of digits from a number."
>> > >  [i]
>> > >  ^{:user/comment "For Euler Problems (Specifically 16)"}
>> > >  (map {\0 0 \1 1 \2 2 \3 3 \4 4 \5 5 \6 6 \7 7 \8 8 \9 9}
>> > >       (str  i)))
>> > Why not use Character/digit, as Saul suggested?
>>
>> Because I'm not a java programmer, so my natural inclination is to use
>> Clojure tools (like the hashmap) rather than Java tools. Since I
>> hadn't seen a solutions using the hashamp - but had seen some more
>> complex variants - I thought this one might be of interest.
>>
>>    <mike
>> --
>> Mike Meyer <m...@mired.org>          http://www.mired.org/consulting.html
>> Independent Software developer/SCM consultant, email for more information.
>>
>> O< ascii ribbon campaign - stop html mail -www.asciiribbon.org
>
> --
> 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