From: kazzarazza003
Subject: converting a number to a list!!!!
Date: 
Message-ID: <f28b411adae5241a06ffe3ee94bc92cd@localhost.talkaboutprogramming.com>
Hi, I don't know how to convert a number (10 or more) to a list. I've tried
using the mod and rem function but I am confused how to use them. Please
help!!! Urgent.

From: Tayssir John Gabbour
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <1097217972.083515.26000@f14g2000cwb.googlegroups.com>
kazzarazza003 wrote:
> Hi, I don't know how to convert a number (10 or more) to a list.
> I've tried using the mod and rem function but I am confused how to
> use them. Please help!!! Urgent.

Beats me. I'd use something painfully hackish like (keep in mind
googlegroups eats code indentation):

(defun natural-number->digits (num)
(labels ((natural-number->text (num)
(format nil "~A" num)))
(loop for i across (natural-number->text num)
collect (parse-integer (string i)))))

(natural-number->digits 0012393290)
(natural-number->digits 0)


Nice thing is that one can be fairly sure this isn't a "homework"
assignment. Well...


MfG,
Tayssir
From: kazzarazza003
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <34fc6f6723717cfaf0c77c47e18bd7f2@localhost.talkaboutprogramming.com>
I'm a uni student, this is not home work really. I don't get much help from
the people that should be teaching me...that's unis for ya.
From: Frank Buss
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <ck5fhu$oos$1@newsreader2.netcologne.de>
"Tayssir John Gabbour" <···········@yahoo.com> wrote:

> (defun natural-number->digits (num)
> (labels ((natural-number->text (num)
> (format nil "~A" num)))
> (loop for i across (natural-number->text num)
> collect (parse-integer (string i)))))

can be done easier:

(defun natural-number->digits (num)
  (map 'list #'(lambda (d) (- (char-code d) (char-code #\0))) 
       (format nil "~A" num))

of course, it is a hack like your solution :-) Would look more elegant with 
a recursive floor algorithm.

"kazzarazza003": where are your problems with mod and rem? What have you 
tried?

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Christophe Rhodes
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <sq4ql5y5or.fsf@cam.ac.uk>
Frank Buss <··@frank-buss.de> writes:

> can be done easier:
>   (- (char-code d) (char-code #\0))) 

Yuk.  (digit-char-p d) is both nicer and specified to work.  :)

Christophe
From: Frank Buss
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <ck5me0$63t$1@newsreader2.netcologne.de>
Christophe Rhodes <·····@cam.ac.uk> wrote:

>> can be done easier:
>>   (- (char-code d) (char-code #\0))) 
> 
> Yuk.  (digit-char-p d) is both nicer and specified to work.  :)

Thanks, I didn't know digit-char-p, and you are right, looks like in Common 
Lisp only (char-code #\0) < (char-code #\1) < ... is specified, but not 
(char-code #\1) - (char-code #\0) = 1.

And another solution:

(defun number->digits (num &optional suffix)
  (multiple-value-bind (q r) (floor num 10)
    (let ((next (cons r suffix)))
      (if (= q 0) next (number->digits q next)))))

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Jim Newton
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <2smqafF1mkkceU1@uni-berlin.de>
won't the LIST function do the conversion you want
(list 10).
What kind of conversion do you want?



kazzarazza003 wrote:
> Hi, I don't know how to convert a number (10 or more) to a list. I've tried
> using the mod and rem function but I am confused how to use them. Please
> help!!! Urgent.
> 
From: Edi Weitz
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <87oejdiuyq.fsf@miles.agharta.de>
On Fri, 08 Oct 2004 02:19:27 -0400, "kazzarazza003" <········@students.unisa.edu.au> wrote:

> Hi, I don't know how to convert a number (10 or more) to a list.

(defun number-to-list (number)
  (declare (ignore number))
  (list))

> I've tried using the mod and rem function but I am confused how to
> use them.

OK, if you need MOD for your assignment:

(defun number-to-list (number)
  (let ((foo (mod number number)))
    (declare (ignore foo))
    (list 42)))

> Please help!!! Urgent.

Sure.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: kazzarazza003
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <78112b3fcece8ea61265d0d58b945d72@localhost.talkaboutprogramming.com>
thanks mate!
From: kazzarazza003
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <524ba166c9942fb965493b2dc1e9d8c8@localhost.talkaboutprogramming.com>
thanks mate!
From: Wade Humeniuk
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <nly9d.20296$j24.16034@clgrps12>
kazzarazza003 wrote:

> Hi, I don't know how to convert a number (10 or more) to a list. I've tried
> using the mod and rem function but I am confused how to use them. Please
> help!!! Urgent.
> 

(defun digits-list (integer &optional (radix 10))
   (assert (typep integer '(integer 0 *)))
   (loop collect (mod integer radix)
         while (> (setf integer (floor (/ integer radix))) 0)))

CL-USER 26 > (digits-list 10)
(0 1)

CL-USER 27 > (digits-list 217148789748)
(8 4 7 9 8 7 8 4 1 7 1 2)

CL-USER 28 > (digits-list 217148789748 16)
(4 15 3 9 3 1 15 8 2 3)

CL-USER 29 > (digits-list 2)
(2)

The digits are reversed (depending on your point of view) in the list.
Easy enough to change.

Wade
From: Wade Humeniuk
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <Aqy9d.51740$N%.21014@edtnps84>
Wade Humeniuk wrote:

> kazzarazza003 wrote:
> 
>> Hi, I don't know how to convert a number (10 or more) to a list. I've 
>> tried
>> using the mod and rem function but I am confused how to use them. Please
>> help!!! Urgent.
>>
> 
> (defun digits-list (integer &optional (radix 10))
>   (assert (typep integer '(integer 0 *)))
>   (loop collect (mod integer radix)
>         while (> (setf integer (floor (/ integer radix))) 0)))
> 

The / is unecessary, try

(defun digits-list (integer &optional (radix 10))
   (assert (typep integer '(integer 0 *)))
   (loop collect (mod integer radix)
         while (> (setf integer (floor integer radix)) 0)))

Wade
From: Frank Buss
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <ck6cdh$aob$2@newsreader2.netcologne.de>
Wade Humeniuk <····································@telus.net> wrote:

> The digits are reversed (depending on your point of view) in the list.
> Easy enough to change.

with reversed results there exists a nice short and fast recursive algorithm,
which I've found first, before adding the &optional argument (see
http://groups.google.de/groups?selm=ck5me0%2463t%241%40newsreader2.netcologne.de ) 

(defun number->digits (num)
  (multiple-value-bind (q r) (floor num 10)
    (cons r (if (= q 0) nil (number->digits q)))))

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Wade Humeniuk
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <gFy9d.51808$N%.3932@edtnps84>
Frank Buss wrote:


> with reversed results there exists a nice short and fast recursive algorithm,
> which I've found first, before adding the &optional argument (see
> http://groups.google.de/groups?selm=ck5me0%2463t%241%40newsreader2.netcologne.de ) 
> 
> (defun number->digits (num)
>   (multiple-value-bind (q r) (floor num 10)
>     (cons r (if (= q 0) nil (number->digits q)))))
> 

Yes, my version does not need to use mod, but can just be

(defun digits-list (integer &optional (radix 10))
   (assert (and (typep integer '(integer 0 *))
                (typep radix '(integer 2 *))))
   (loop for (quotient remainder) = (multiple-value-list (floor integer radix))
         collect remainder
         while (> (setf integer quotient) 0)))

CL-USER 41 > (digits-list 217148789748)
(8 4 7 9 8 7 8 4 1 7 1 2)

CL-USER 42 > (digits-list 217148789748 2)
(0 0 1 0 1 1 1 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 0 0 1 1)

CL-USER 43 > (digits-list 1)
(1)

CL-USER 44 >

(These are the times I wish loop would have some provision for multiple return values.)

Wade
From: Gareth McCaughan
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <87hdp4vom4.fsf@g.mccaughan.ntlworld.com>
"kazzarazza003" <········@students.unisa.edu.au> writes:

> Hi, I don't know how to convert a number (10 or more) to a list. I've tried
> using the mod and rem function but I am confused how to use them. Please
> help!!! Urgent.

Why was it urgent?

-- 
Gareth McCaughan
.sig under construc
From: Pascal Bourguignon
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <878yagxb73.fsf@thalassa.informatimago.com>
Gareth McCaughan <················@pobox.com> writes:

> "kazzarazza003" <········@students.unisa.edu.au> writes:
> 
> > Hi, I don't know how to convert a number (10 or more) to a list. I've tried
> > using the mod and rem function but I am confused how to use them. Please
> > help!!! Urgent.
> 
> Why was it urgent?

The usual case is the guy that had add big booze party and forgot his
homework.  At 2:15 in the night, he realizes that his got only 5:45
hour to do it and can't possibly learn one week of lessons, eliminiate
the alcohol in his system, do his homeworks, get some sleep and be
ready for the morning class.  So with a little luck, he can outsource
unessential tasks over the Internet and try to be presentable for the
next morning.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Voting Democrat or Republican is like choosing a cabin in the Titanic.
From: Gareth McCaughan
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <87r7o7u2nq.fsf@g.mccaughan.ntlworld.com>
Pascal Bourguignon <····@mouse-potato.com> writes:

> Gareth McCaughan <················@pobox.com> writes:
> 
> > "kazzarazza003" <········@students.unisa.edu.au> writes:
> > 
> > > Hi, I don't know how to convert a number (10 or more) to a list. I've tried
> > > using the mod and rem function but I am confused how to use them. Please
> > > help!!! Urgent.
> > 
> > Why was it urgent?
> 
> The usual case is the guy that had add big booze party and forgot his
> homework.  At 2:15 in the night, he realizes that his got only 5:45
> hour to do it and can't possibly learn one week of lessons, eliminiate
> the alcohol in his system, do his homeworks, get some sleep and be
> ready for the morning class.  So with a little luck, he can outsource
> unessential tasks over the Internet and try to be presentable for the
> next morning.

I know. But Mr Kazzarazza insisted that this wasn't a
homework problem. I was wondering what else would have
made it urgent.

-- 
Gareth McCaughan
.sig under construc
From: Pascal Bourguignon
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <874ql3wpzk.fsf@thalassa.informatimago.com>
Gareth McCaughan <················@pobox.com> writes:
> > > Why was it urgent?
> > 
> > The usual case is the guy that had add big booze party and forgot his
> > homework.  At 2:15 in the night, he realizes that his got only 5:45
> > hour to do it and can't possibly learn one week of lessons, eliminiate
> > the alcohol in his system, do his homeworks, get some sleep and be
> > ready for the morning class.  So with a little luck, he can outsource
> > unessential tasks over the Internet and try to be presentable for the
> > next morning.
> 
> I know. But Mr Kazzarazza insisted that this wasn't a
> homework problem. I was wondering what else would have
> made it urgent.

May be he had only half an hour of life remaining and wanted to get an
answer for the last exam?

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Voting Democrat or Republican is like choosing a cabin in the Titanic.
From: Joe Marshall
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <llecnhu1.fsf@ccs.neu.edu>
Pascal Bourguignon <····@mouse-potato.com> writes:

> Gareth McCaughan <················@pobox.com> writes:
>> > > Why was it urgent?
>> > 
>> > The usual case is the guy that had add big booze party and forgot his
>> > homework.  At 2:15 in the night, he realizes that his got only 5:45
>> > hour to do it and can't possibly learn one week of lessons, eliminiate
>> > the alcohol in his system, do his homeworks, get some sleep and be
>> > ready for the morning class.  So with a little luck, he can outsource
>> > unessential tasks over the Internet and try to be presentable for the
>> > next morning.
>> 
>> I know. But Mr Kazzarazza insisted that this wasn't a
>> homework problem. I was wondering what else would have
>> made it urgent.
>
> May be he had only half an hour of life remaining and wanted to get an
> answer for the last exam?

You have been imprisoned by an evil scientist and he gives you the
following options:  he will kill one thousand people selected at
random, or he will kill you best friend.  If you refuse to decide, he
will kill both your best friend *and* the thousand random people.
However, he adds this unusual condition:  if you can persuade some
random on usenet to write an algorithm to convert a number to a list
within 5 minutes, he will release all of you.....
 
From: Raffael Cavallaro
Subject: Re: converting a number to a list!!!!
Date: 
Message-ID: <2004101301403375249%raffaelcavallaro@pasdespamsilvousplaitdotmaccom>
On 2004-10-12 10:15:18 -0400, Joe Marshall <···@ccs.neu.edu> said:

> You have been imprisoned by an evil scientist and he gives you the
> following options:  he will kill one thousand people selected at
> random, or he will kill you best friend.  If you refuse to decide, he
> will kill both your best friend *and* the thousand random people.
> However, he adds this unusual condition:  if you can persuade some
> random on usenet to write an algorithm to convert a number to a list
> within 5 minutes, he will release all of you.....

I think you're right -  this sounds more plausible than that far 
fetched homework theory to me.