yes... it would be better.
On Sun, Jan 20, 2013 at 2:30 AM, David Brown wrote:
> Qiu Xiafei writes:
>
> > (defn num->digits
> > [num]
> > (loop [n num res []]
> > (if (zero? n)
> > res
> > (recur (long (/ n 10)) (cons (mod n 10) res)
>
> How about (quot n 10) instead o
Qiu Xiafei writes:
> (defn num->digits
> [num]
> (loop [n num res []]
> (if (zero? n)
> res
> (recur (long (/ n 10)) (cons (mod n 10) res)
How about (quot n 10) instead of (long (/ n 10))? No sense in the
extra step.
David
--
You received this message because you ar
(defn num->digits
[num]
(loop [n num res []]
(if (zero? n)
res
(recur (long (/ n 10)) (cons (mod n 10) res)
在 2011年2月17日星期四UTC+8下午1时29分10秒,Andreas Kostler写道:
>
> Is there an easy and idiomatic way of getting the digits of a number in
> clojure?
>
> (defn explode-to-digits
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
wrote:
> How about using the Java api Character/getNumbericValue, like so:
>
> (
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 wrote:
> On Thu, 17 Feb 2011 15:27:47 -0600
>
> Michael Gardner w
On Thu, 17 Feb 2011 15:27:47 -0600
Michael Gardner 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 \
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)))
>
> No assumption about repr
On Thu, 17 Feb 2011 10:26:05 -0800 (PST)
JMatt wrote:
> On Feb 16, 10:29 pm, Andreas Kostler
> 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:
My turn...
(defn to-digits
"Create a seq of digit
On Feb 16, 10:29 pm, Andreas Kostler
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)"}
On Thu, Feb 17, 2011 at 1:39 AM, Shantanu Kumar
wrote:
> On Feb 17, 11:09 am, Ken Wesson wrote:
>> On Thu, Feb 17, 2011 at 12:29 AM, Andreas Kostler
>>
>> wrote:
>> > Is there an easy and idiomatic way of getting the digits of a number in
>> > clojure?
>>
>> > (defn explode-to-digits [number]
>
On Thu, Feb 17, 2011 at 12:29 AM, Andreas Kostler
wrote:
> Is there an easy and idiomatic way of getting the digits of a number in
> clojure?
>
> (defn explode-to-digits [number]
> (map #(- (int %) (int \0)) (str number)))
> (explode-to-digits 123456)
> => (1 2 3 4 5 6)
>
> Seems a bit clu
On Feb 17, 11:39 am, Shantanu Kumar wrote:
> On Feb 17, 11:09 am, Ken Wesson wrote:
>
>
>
>
>
>
>
>
>
> > On Thu, Feb 17, 2011 at 12:29 AM, Andreas Kostler
>
> > wrote:
> > > Is there an easy and idiomatic way of getting the digits of a number in
> > > clojure?
>
> > > (defn explode-to-digits
On Feb 17, 11:09 am, Ken Wesson wrote:
> On Thu, Feb 17, 2011 at 12:29 AM, Andreas Kostler
>
> wrote:
> > Is there an easy and idiomatic way of getting the digits of a number in
> > clojure?
>
> > (defn explode-to-digits [number]
> > (map #(- (int %) (int \0)) (str number)))
> > (explod
On Feb 17, 6:29 am, Andreas Kostler
wrote:
> Is there an easy and idiomatic way of getting the digits of a number in
> clojure?
>
> (defn explode-to-digits [number]
> (map #(- (int %) (int \0)) (str number)))
> (explode-to-digits 123456)
> => (1 2 3 4 5 6)
Sorry, my first answer was care
Hi Saul,
> (defn explode-to-digits [number]
>(seq (str number)))
This gives you a sequence of character representations for the digits e.g:
(explode-to-digits 1234)
=> (\1 \2 \3 \4)
On 17/02/2011, at 4:01 PM, Saul Hazledine wrote:
> On Feb 17, 6:29 am, Andreas Kostler
> wrote:
>> Is there
On Feb 17, 6:29 am, Andreas Kostler
wrote:
> Is there an easy and idiomatic way of getting the digits of a number in
> clojure?
>
> (defn explode-to-digits [number]
> (map #(- (int %) (int \0)) (str number)))
> (explode-to-digits 123456)
> => (1 2 3 4 5 6)
I'd do it this way:
(defn expl
Is there an easy and idiomatic way of getting the digits of a number in clojure?
(defn explode-to-digits [number]
(map #(- (int %) (int \0)) (str number)))
(explode-to-digits 123456)
=> (1 2 3 4 5 6)
Seems a bit clunky...
Andreas
--
You received this message because you are subscribed
17 matches
Mail list logo