Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!newsserver.jvnc.net!howland.reston.ans.net!usc!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!sfsuvax1.sfsu.edu!emclean
From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Re: j combinations
Message-ID: <1993Feb21.102205.2369@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <1993Feb19.085518.1@wharton.upenn.edu>
Date: Sun, 21 Feb 1993 10:22:05 GMT
Lines: 27

   NB.    I liked Raul's method of selecting integers whose binary
   NB.    representations have two ones. Building on this stragegy I've
   NB.    devised a more efficient solution. Just 0!:2 this.
   
   greyCode =. #:@(#~ 0&~:)@,@(</~ * +/~)@(2&^)@i.

   9!:3(5) NB. For displays
   greyCode 4  NB. check out GC :
   
   NB. Compare methods
   (5) 6!:2 ' #. ((+/ = 2:)"1 # ]) #: i. 256'      NB. Rauls's time
       7!:2 ' #. ((+/ = 2:)"1 # ]) #: i. 256'      NB. Raul's space
   (5) 6!:2 'greyCode 8'     NB. Emmett's time
       7!:2 'greyCode 8'     NB. Emmett's space
   
   NB. As for the question of finding the averages of all n choose 2
   NB. sets with two elements :

   mean =.  +/ % #
   avgOv2Sets =.mean"1@( #"1~ greyCode@# ) 
   displAvgOv2Sets =.(;~ ,:@mean"1)@(greyCode@# #"1 ]) 

   NB. For example :
   avgOv2Sets 4 5 6 9
   displAvgOv2Sets 4 5 6 9

   <'Emmett'
