an interesting variation for pairs excluding "self pairs", but with swaps.
(-.@= #&, j./~)@i. 5
0j1 0j2 0j3 0j4 1 1j2 1j3 1j4 2 2j1 2j3 2j4 3 3j1 3j2 3j4 4 4j1 4j2 4j3
+. gets it in pair form
(#~ </&+.) (-.@= #&, j./~)@i. 5 NB. to get unique pairs.
0j1 0j2 0j3 0j4 1j2 1j3 1j4 2j3 2j4 3j4
----- Original Message -----
From: Kip Murray <[email protected]>
To: "[email protected]" <[email protected]>
Sent: Friday, December 18, 2015 10:15 AM
Subject: Re: [Jprogramming] Getting all pairs of integers up to some value
K
[: ([: +. , #~ [: </"1 [: +."0 ,) i. j./ i.
K 4
0 1
0 2
0 3
1 2
1 3
2 3
Uses complex numbers.
--Kip Murray
On Friday, December 18, 2015, Ben Gorte - CITG <[email protected]>
wrote:
> Two of my favorite constructs are 4$.$. and each. Therefore:
>
> (#~</"1)4$.$.5 5$1
>
> or:
>
> ;(i.,.]) each ;/i.5
>
> The second is more efficient, despite boxes.
>
> Ben
> ________________________________________
> From: [email protected] <javascript:;> [
> [email protected] <javascript:;>] on behalf of
> 'Jon Hough' via Programming [[email protected] <javascript:;>]
> Sent: Friday, December 18, 2015 13:58
> To: Programming Forum
> Subject: [Jprogramming] Getting all pairs of integers up to some value
>
> I've spent an hour on this, and am frustrated that I couldn't figure out a
> way to do it (without using for_j or while).
>
> I want to get all pairs ( pair order not important e.g. 2 3 is the same as
> 3 2) of integers up to some value.
>
> e.g. up to 4:
>
> 0 1
> 0 2
> 0 3
> 1 2
> 1 3
> 2 3
>
> in frustration this is what I came up with (for the case of 10):
> /:~ ~. /:~"1 (1000 # 2) ? 10
>
> which works but is not a very good solution.
>
> Any nice solutions?
>
> Thanks,
>
> Jon
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Sent from Gmail Mobile
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm