From: William James
Subject: Re: Another From the Trenches Kenny Gotta Be a Better Way Challenge
Date: 
Message-ID: <b41a3301-09e8-4330-948c-81f1c5fdbf3d@i29g2000prf.googlegroups.com>
Ken Tilton 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))

(= shuffled  (sort (fn (a b) (> 0.5 (rand))) nums))
(prn (find [~some _ used] shuffled))