On Feb 16, 10:29 pm, Andreas Kostler
<andreas.koestler.le...@gmail.com> wrote:
> Is there an easy and idiomatic way of getting the digits of a number in 
> clojure?

Here is my attempt at this from a few months ago:

(defn to-digit
  "Create a seq of digits from a number."
  ^{:user/comment "For Euler Problems (Specifically 16)"}
  [i & {:keys [type] :or {type int}}]
   (let [ss (str i)] (map type (map (fn [s] (- (int s) 48)) ss))))

I took a more pragmatic approach to this problem and just assumed the
representation for digits was ASCII. It's possible to simplify this
some but, as is, it'll take seqs of characters or strings. At the time
I remember thinking this function should really return bytes or shorts
or something smaller than an int. Thus the :type option.


JMatt

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