>From http://www.jsoftware.com/pipermail/programming/2008-January/009488.html


comb3=: [:; [:(,.&.><@;\.)/ >:@[EMAIL PROTECTED]

   (pairi -:2&comb3)100
1

   rnk2 5&ts&>'pairi y';'pair2 y';'2&comb3 y'[y=.1000
2  25.91 2.61     0.988 2.517e7
1   1.26 1.00     0.048 9.640e6
0   1.00 1.00     0.038 9.636e6


R.E. Boss


-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Arie Groeneveld
Verzonden: vrijdag 7 november 2008 12:13
Aan: Programming forum
Onderwerp: Re: [Jprogramming] pairs


pair2=:([:;],."0 _&.>[:<\.1&+)@i.@<:

   (pair2-:pairi) 100
1

=@@i


Matthew Brand schreef:
> 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
>
>
>   
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to