From: Drew Krause
Subject: simple loop question
Date: 
Message-ID: <Khlff.9913$2y.8512@newsread2.news.atl.earthlink.net>
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!

From: Pascal Costanza
Subject: Re: simple loop question
Date: 
Message-ID: <3u6666Fvhdu5U1@individual.net>
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/
From: Peder O. Klingenberg
Subject: Re: simple loop question
Date: 
Message-ID: <ks8xvmca3m.fsf@beto.netfonds.no>
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.
From: Lars Brinkhoff
Subject: Re: simple loop question
Date: 
Message-ID: <857jb6hwbi.fsf@junk.nocrew.org>
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))