From: William James
Subject: Re: Another From the Trenches Kenny Gotta Be a Better Way Challenge
Date: 
Message-ID: <85429be7-b7b2-45ae-95bb-34977c5d49fc@u72g2000hsf.googlegroups.com>
On Mar 21, 3:58 pm, Ken Tilton <···········@optonline.net> wrote:
> (let* ((nums (list 0 1 2 3 4 5 6 7))
>        (used (make-array (length nums)
>                :element-type 'bit
>                :initial-element 0)))
>    (labels ((show-one (depth)
>               (when (find 0 used)
>                 (let ((one (loop thereis
>                                  (loop for n in nums
>                                      unless (= 1(bit used n))
>                                      when (zerop (random (length nums)))
>                                      return n))))
>                   (print one)
>                   (setf (bit used one) 1)
>                   (show-one (1+ depth))))))
>      (show-one 0)))
>
> This is somewhat distorted, but the labeled fn show-one is what I really
> have to do: given a mask and a list of numbers some of whom have already
> been "used" indicated by (= 1 (bit mask <that number>)), pick a number
> at random from those still unused. Without consing.
>
> In case it is confusing above, in reality there will be just a dozen
> random numbers under about 5000, and the mask will be a 5000 bit mask.
>
> All I have so far is trying numbers at random in a tight loop.

Arc:

(= nums '(9 22 37 54 61 78 83 92))
(= used '(22 54 83))

(= unused (rem [some _ used] nums))
(prn (random-elt unused))
From: Barry Margolin
Subject: Re: Another From the Trenches Kenny Gotta Be a Better Way Challenge
Date: 
Message-ID: <barmar-3754BE.01585925032008@newsgroups.comcast.net>
In article 
<····································@u72g2000hsf.googlegroups.com>,
 William James <·········@yahoo.com> wrote:

> On Mar 21, 3:58 pm, Ken Tilton <···········@optonline.net> wrote:
> > (let* ((nums (list 0 1 2 3 4 5 6 7))
> >        (used (make-array (length nums)
> >                :element-type 'bit
> >                :initial-element 0)))
> >    (labels ((show-one (depth)
> >               (when (find 0 used)
> >                 (let ((one (loop thereis
> >                                  (loop for n in nums
> >                                      unless (= 1(bit used n))
> >                                      when (zerop (random (length nums)))
> >                                      return n))))
> >                   (print one)
> >                   (setf (bit used one) 1)
> >                   (show-one (1+ depth))))))
> >      (show-one 0)))
> >
> > This is somewhat distorted, but the labeled fn show-one is what I really
> > have to do: given a mask and a list of numbers some of whom have already
> > been "used" indicated by (= 1 (bit mask <that number>)), pick a number
> > at random from those still unused. Without consing.
                                       ^^^^^^^^^^^^^^^
> >
> > In case it is confusing above, in reality there will be just a dozen
> > random numbers under about 5000, and the mask will be a 5000 bit mask.
> >
> > All I have so far is trying numbers at random in a tight loop.
> 
> Arc:
> 
> (= nums '(9 22 37 54 61 78 83 92))
> (= used '(22 54 83))

He said that the used numbers are indicated with a bit mask, not a list.

> 
> (= unused (rem [some _ used] nums))
> (prn (random-elt unused))

The assignment to unused appears to cons.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***