Newsgroups:   comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!spool.mu.edu!uwm.edu!rpi!utcsri!geac!itcyyz!yrloc!intern
From:         eem@ipsaint.ipsa.reuter.COM (Mcdonnell, Eugene E.)
Subject:      cup of coffee
Message-ID: <1993Feb11.052958.2388@yrloc.ipsa.reuter.COM>
Sender: intern@yrloc.ipsa.reuter.COM (Intern via QUADRAM)
Reply-To:     eem@ipsaint.ipsa.reuter.COM (Mcdonnell, Eugene E.)
Organization: Reuters Information Services (Canada)
Date:         11 Feb 93 05:00:05 UT
Lines: 36


-----------Message forwarded from IPSA Mailbox-------------


no. 6967506 filed  4.50.18  thu 11 feb 1993
from eem
to   uclapl
subj cup of coffee

 As a workaround for the nonavailability of deal in early APL\360 (circa 1966)
 I wrote essentially the following APL version for x deal y:

 a. generate y copies of some large integer, say 1e9
 b. generate a random number for each of these, using roll
 c. grade these
 d. take the first x elements of the grade

 When I showed this to Dick Lathwell several years after deal was available,
 he said that it was quite close to the machine language implementation he had
 come up with.  There is a certain bias in this in the way grade works on
 repeated values in a given result of the roll primitive, but the probability
 of repeated values for small y (<1e6) is small.  It qualifies as a smart
 algorithm, in Bernecky's terms, as it performs in linear time. 

 A J version of this is

 deal=.[{./:@(?@(#&1e9@]))
 deal=.[ {.   /:      @    (?    @    (#    &    1e9 @    ]))
 deal= x take upgrade atop (roll atop (copy with 1e9 atop y))


-----------------------------------------------------------
This posting is forwarded from an internal Reuters mailbox.
No statement or opinion contained herein should be taken as
being Reuters policy, or even as being approved by Reuters,
in any way.
