Your version is incorrect? (g allperms 4) -: (A.&i.~ -:&!)4 0
(g allperms 4) ; (A.&i.~ -:&!)4 ┌───────┬───────┐ │0 1 2 3│0 1 2 3│ │0 1 3 2│0 1 3 2│ │0 2 1 3│0 2 1 3│ │0 2 3 1│0 2 3 1│ │0 3 1 2│0 3 1 2│ │0 3 2 1│0 3 2 1│ │1 0 2 3│1 0 2 3│ │1 0 3 2│1 0 3 2│ │1 2 0 3│1 2 0 3│ │1 3 0 2│1 2 3 0│ │2 0 1 3│1 3 0 2│ │2 1 0 3│1 3 2 0│ └───────┴───────┘ - Both 0 2 3 1 and its reversal occurs in your result - Neither 2 0 1 3 nor its reversal occurs in your result On Wed, Jun 15, 2016 at 4:16 PM, Mike Day <[email protected]> wrote: > I like your version of all perms; it's even more elegant than > tap =: i.@! A. i. > > Anyway, a quite elegant variant produces what I think you > require, here with a transpose to save lines: > |:(A.&i.~ -:&!)4 > 0 0 0 0 0 0 1 1 1 1 1 1 > 1 1 2 2 3 3 0 0 2 2 3 3 > 2 3 1 3 1 2 2 3 0 3 0 2 > 3 2 3 1 2 1 3 2 3 0 2 0 > > Any use? > Mike > > > On 15/06/2016 22:42, Louis de Forcrand wrote: > >> Hi, >> >> How would you go about generating all unique permutations of a list, >> while counting each perm and its reversal as one? >> A perhaps clearer (but less efficient) way of doing this is generating >> all permutations and then removing (reversed) duplicates: >> >> allperms=: (A.&i.~ !) 4 NB. 4 is just an example >> ]those_I_want=: ([: {."2@~. (/:~@,: |.)"1) allperms >> 0 1 2 3 >> 0 1 3 2 >> 0 2 1 3 >> 0 2 3 1 >> 0 3 1 2 >> 0 3 2 1 >> 1 0 2 3 >> 1 0 3 2 >> 1 2 0 3 >> 1 3 0 2 >> 2 0 1 3 >> 2 1 0 3 >> >> There is surely a better way to do this! >> >> Thanks, >> Louis >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
