I have found that Anagram Index works well for this kind of problem.
It doesn't have indices as such, but does the job.

(i.!4)A.2 3 5 7

2 3 5 7

2 3 7 5

2 5 3 7

2 5 7 3

2 7 3 5

2 7 5 3

3 2 5 7

3 2 7 5

3 5 2 7

3 5 7 2

3 7 2 5

3 7 5 2

5 2 3 7

5 2 7 3

5 3 2 7

5 3 7 2

5 7 2 3

5 7 3 2

7 2 3 5

7 2 5 3

7 3 2 5

7 3 5 2

7 5 2 3

7 5 3 2

On Wed, Dec 5, 2018 at 6:46 PM Skip Cave <s...@caveconsulting.com> wrote:

> I want to generate all the 1, 2, 3, & 4 permutations of 4 items.
> I can generate the indices:
>
> (1 2 3 4 perm each 4)
>
> ┌─┬───┬─────┬───────┐
>
> │0│0 1│0 1 2│0 1 2 3│
>
> │1│1 0│0 2 1│0 1 3 2│
>
> │2│0 2│1 0 2│0 2 1 3│
>
> │3│2 0│1 2 0│0 2 3 1│
>
> │ │0 3│2 0 1│0 3 1 2│
>
> │ │3 0│2 1 0│0 3 2 1│
>
> │ │1 2│0 1 3│1 0 2 3│
>
> │ │2 1│0 3 1│1 0 3 2│
>
> │ │1 3│1 0 3│1 2 0 3│
>
> │ │3 1│1 3 0│1 2 3 0│
>
> │ │2 3│3 0 1│1 3 0 2│
>
> │ │3 2│3 1 0│1 3 2 0│
>
> │ │ │0 2 3│2 0 1 3│
>
> │ │ │0 3 2│2 0 3 1│
>
> │ │ │2 0 3│2 1 0 3│
>
> │ │ │2 3 0│2 1 3 0│
>
> │ │ │3 0 2│2 3 0 1│
>
> │ │ │3 2 0│2 3 1 0│
>
> │ │ │1 2 3│3 0 1 2│
>
> │ │ │1 3 2│3 0 2 1│
>
> │ │ │2 1 3│3 1 0 2│
>
> │ │ │2 3 1│3 1 2 0│
>
> │ │ │3 1 2│3 2 0 1│
>
> │ │ │3 2 1│3 2 1 0│
>
> └─┴───┴─────┴───────┘
>
> How can I apply those indices to a 4-element vector consisting of the
> integers 1 3 5 7, in order to generate all the 1, 2, 3, & 4 permutations of
> those 4 integers?
>
> (1 2 3 4 perm each 4) each {1 3 5 7
>
> |domain error: each
>
> | (1 2 3 4 perm each 4) each{1 3 5 7
>
>
> Fail!
>
>
> Skip
> ----------------------------------------------------------------------
> 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