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!bogus.sura.net!darwin.sura.net!haven.umd.edu!socrates!socrates!rockwell
From: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Subject: Re: j combinations
In-Reply-To: siler@wharton.upenn.edu's message of 19 Feb 93 13:55:18 GMT
Message-ID: <ROCKWELL.93Feb21022244@socrates.umd.edu>
Sender: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Organization: Traveller
References: <1993Feb19.085518.1@wharton.upenn.edu>
Date: Sun, 21 Feb 1993 07:22:44 GMT
Lines: 32

Jack Siler:
.  Suppose I'd like the 4-choose-2 distinct logical vectors:
.     1 1 0 0
.     1 0 1 0
.     1 0 0 1
.     0 1 1 0
.     0 1 0 1
.     0 0 1 1  (Is this Grey code? reflected Grey code? My Grey cells are
.                                                     fast disappearing)
.  What's the J way of generating such vectors?

To generate your "two of four" vectors, I'd generate all the 4 element
bit vectors then select those with two ones:
   ((+/ = 2:)"1 # ]) #: i. 16
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0

Grey code is somewhat different [you are counting, but can only change
one bit at a time].

.  When is it smart to do it iteratively/recursively instead of
.  "directly"?  ; if, for example, I want the means of all subsets of
.  size k from a (large) batch of n numbers.

Play with time and space measurements and decide for yourself -- note
that crossover points may be machine dependent.

Raul
