[Jprogramming] Getting all pairs of integers up to some value
Joe Bogner
joebogner at gmail.com
Fri Dec 18 13:30:27 UTC 2015
For very low range numbers (less than 10), this could work
The problem with this approach is that it generates all permutations !n
(~.@(] /:"1 ])@(2]\])@;@(i.@!@# A. ]) i.) 4
On Fri, Dec 18, 2015 at 7:58 AM, 'Jon Hough' via Programming
<programming at jsoftware.com> wrote:
> 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
More information about the Programming
mailing list