On 7/13/2017, Robert L. wrote:
> Lars Brinkhoff wrote:
>
> > > 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))
>
> (use miscmacros) ; inc!
> (use srfi-121) ; generators
> (use holes) ; ##
>
> (generator->list
> (let ((s 0))
> (gtake-while ##(and (<= s 50) (inc! s !!)) ##(random 10))))
>
> ===>
> (1 4 1 4 9 3 8 5 3 5 6 1 9)
(use foof-loop)
(define (go)
(loop ((let x (random 10))
(y 0 (+ y x))
(until (> y 50))
(for r (listing x)))
=> r))
#;4> (go)
(2 9 0 4 9 9 3 0 9 0 9)
#;5> (go)
(2 2 3 0 2 5 8 7 2 8 4 9)
#;6> (apply + '(2 2 3 0 2 5 8 7 2 8 4 9))
52
(define (test)
(define r (go))
(if (and (> (apply + r) 50)
(<= (apply + (butlast r)) 50))
(display ".")
(print "bad result: " r)))
(use miscmacros) ; repeat
(repeat 70 (test))
===>
......................................................................
--
Amazon bans book after it received 300 5-star reviews.
http://www.tomatobubble.com/worldwarii.html