... and here’s an explicit function to generate the minimal solution, and indeed the minimal solutions for each starting value:
rp =: 3 : 0 NB. generate minimal restricted perm where adjacent pairs' sums .ne. 3 cur =. p =. 4 | y NB. suitable seed l =. cur -.~ i. 4 while. #l do. p =. p, cur =. cur {.@(] #~ 3 ~: +) l l =. l -. cur end. p ) rp 0 0 1 3 2 rp"0 i.4 NB. the lower perms for each starting value 0 1 3 2 1 0 2 3 2 0 1 3 3 1 0 2 Just append the reverse of every row for all solutions, $(,|."1)rp"0 i.4 8 4 Cheers, Mike Sent from my iPad > On 25 May 2020, at 13:15, Mike Day <mike_liz....@tiscali.co.uk> wrote: > > I think there are 8 solutions. > Given one, minimal, solution, 0 1 3 2, how about this? > > ((,|."1)@:(|."0 1~i.@#))'0132' > 0132 > 1320 > 3201 > 2013 > 2310 > 0231 > 1023 > 3102 > > Any use? > > Mike > > Sent from my iPad > >> On 25 May 2020, at 12:47, Brian Schott <schott.br...@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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm