I should think "comb" could serve your purposes.
There's a comb verb in ~\packages\stats\statfns.ijs
while I use a quicker version which I think was suggested
by R E Boss, but might have been from someone else:
comb =: 4 : 0 NB. can memoise with M.
if. (x>:y)+.0=x do.
i.(x<:y),x
else.
(0,.x comb&.<: y),1+x comb y-1
end.
)
There are lots of other variants mentioned in Jprogramming
correspondence.
For pairs you could use
pairi =: 2&comb
But your verb is pretty fast, uses slightly less space, and gives
identical results as far as I can see.
Mike
Matthew Brand wrote:
Hi All,
I came up with this program to generate pairs of indices to select all
unique pairs from a list. Is there a built in J way to do this? I
looked at C. and A. but could not see how to achieve the below.
Thanks,
Matthew.
pairi =: ( ( ] #~ [: (~:/)"1 ] ) [: ~. [: /:~"1 (]#[:i.]) ,."0 *:$i.)
NB. 2 item list has one pair with indices 0 and 1
pairi 2
0 1
NB. 3 item list has 3 pairs with these indices:
pairi 3
0 1
0 2
1 2
NB. 4 item list has 6 pairs with these indices:
pairi 4
0 1
0 2
0 3
1 2
1 3
2 3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
------------------------------------------------------------------------
Internal Virus Database is out of date.
Checked by AVG - http://www.avg.com
Version: 8.0.175 / Virus Database: 270.8.5/1764 - Release Date: 03/11/2008 07:46
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm