[Jprogramming] restricting permutations
Skip Cave
skip at caveconsulting.com
Mon May 25 18:53:39 UTC 2020
ssmb=:+./@E.
l21=.-.1 1 ssmb"1+./"2]1 2=/"1 n=.perm 4
l30=.-.1 1 ssmb"1+./"2]0 3=/"1 n
n#~l30*.l21
0 1 3 2
0 2 3 1
1 0 2 3
1 3 2 0
2 0 1 3
2 3 1 0
3 1 0 2
3 2 0 1
Skip Cave
Cave Consulting LLC
On Mon, May 25, 2020 at 6:48 AM Brian Schott <schott.brian at gmail.com> wrote:
> I want all permutations of i. 4 for which 0 and 3 cannot be adjacent, nor
> can 1 and 2. My idea is to create a as follows to describe my situation.
>
> ]a =. 0 1 1 0,:i. 4
>
> 0 1 1 0
>
> 0 1 2 3
>
>
> Next I created b and rotations on b to list the possibilities I can think
> of. So I can think of 6 permutations. Are there more and is there a better
> way to generate the real qualifying permutations?
> ]b =. 0 1 3 2 ,:1 0 2 3
> 0 1 3 2
> 1 0 2 3
> 1|."1 b
> 1 3 2 0
> 0 2 3 1
> _1|."1 b
> 2 0 1 3
> 3 1 0 2
> --
> (B=)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
More information about the Programming
mailing list