[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 99 bottles
On Tuesday, October 8, 2002, at 03:59 PM, Bruce Lewis wrote:
> Daniel Weinreb <DLWeinreb@attbi.com> writes:
>
>> They both handle "no bottles", but they also both blow it with "one
>> bottles". Oh well.
>
> I think that's acceptable, given the nature of the problem.
>
> <!-- Bruce Lewis doubts he could use correct grammar after 98 beers.
> -->
indeed...
(define (b-l-string num)
(cond [(= num 0) "no more bottles"]
[(= num 1) "one bottle"]
[else (string-append (number->string num) " bottles")]))
(let drink ([beers-left 99] [beers-actually-drunk 0])
(let ([this (b-l-string beers-left)])
(printf "~a of beer on the wall, ~a of beer; take one down, pass it
around, ...\n" this this))
(when (>= beers-left 0)
(drink (- beers-left (+ 1 (round (/ (random (+ beers-actually-drunk
1)) 10)))) (+ beers-actually-drunk 1))))