There must be a concise way to do this, but my brain's not working
properly this morning:
use LOOP to collect random integers into a list until the sum of that
list exceeds a constant (say 50).
Any help appreciated! Thanks!
Drew Krause wrote:
> There must be a concise way to do this, but my brain's not working
> properly this morning:
>
> use LOOP to collect random integers into a list until the sum of that
> list exceeds a constant (say 50).
>
> Any help appreciated! Thanks!
(loop for n = (random 10)
collect n
sum n into sum
until (>= sum 50))
Pascal
--
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/
Drew Krause <········@mindspring.com> writes:
> There must be a concise way to do this, but my brain's not working
> properly this morning:
>
> use LOOP to collect random integers into a list until the sum of that
> list exceeds a constant (say 50).
>
> Any help appreciated! Thanks!
Sounds an awful lot like homework, but what the hell, it's Friday.
CL-USER> (defparameter *limit* 50)
*LIMIT*
CL-USER> (loop for i = (random *limit*)
sum i into total
collect i
until (> total *limit*))
(28 14 25)
CL-USER> (loop for i = (random *limit*)
sum i into total
collect i
until (> total *limit*))
(39 39)
CL-USER> (loop for i = (random *limit*)
sum i into total
collect i
until (> total *limit*))
(44 4 35)
...Peder...
--
I wish a new life awaited _me_ in some off-world colony.
Drew Krause <········@mindspring.com> writes:
> use LOOP to collect random integers into a list until the sum of that
> list exceeds a constant (say 50).
(loop for x = (random 10) collect x sum x into y until (> y 50))