not completely clear what you are doing.

permutations with repeats can be indexed, but there is a better number than

2 3 4 0 1 { 0 0 1 1 1


posted this fairly recently

permC =: (# %&((*/))&:(!M.@x:) 1 -.~ #/.~)
del1 =: i.~ ({. , >:@[ }. ]) ]

permNF =: 2 {:: (] (((0 {:: [) - ] * (1 {:: [) ([ i. {~) (0 {:: [) <.@% ]) ; [ 
((] ,~ 2 {:: [) ;~ ] del1 1 {:: [)  (1 {:: [)  {~ (0 {:: [) <.@% ]) 1 (permC % 
#)@{:: ])^:(0 < 1 #@{:: ])^:_@:(a:,~ ;) f.

permN =: +/@:(((permC % #) * 0 i.~ /:)\.) f.



(/:~ permNF~ permN) 1 1 1 0 0
1 1 1 0 0

the all permutations version of permN indexing function is:  (not the fastest, 
but produces sorted)

rp1 =: (] (] <@; $:^:(1<#)@del1~)"1 0 ~.@])
untreep =: (({.,"0 1 $:^:(1<L.)@}.)&>)
rperm6 =: (a: ;"1@(]#~-.@e."1) ,&.:(<"1)@:untreep@:rp1)


rperm6 0 0 1 1 1
0 0 1 1 1
0 1 0 1 1
0 1 1 0 1
0 1 1 1 0
1 0 0 1 1
1 0 1 0 1
1 0 1 1 0
1 1 0 0 1
1 1 0 1 0
1 1 1 0 0


This might be an alternate version of what you want

#. 1 1 1 0 0 
28


Basically, there is not much sense in looking at a 120 long list of things 
related to this vector, as it is not part of a 120 long group.

----- Original Message -----
From: Louis de Forcrand <[email protected]>
To: [email protected]
Sent: Sunday, May 29, 2016 5:12 PM
Subject: [Jprogramming] All unique permutations of a logical vector

Is there a faster (and relatively concise) way of generating

(~.@:A.~ i.@!@#) b
where b is a logical vector (of 0s and 1s)?
There are obviously (+/ ! #) b vectors in the result, but I can't
see any relation in their anagram indices:

   I.@(-:"1/~ ~.)@(A. ~i.@!@#) 1 1 1 0 0
0  1  6  7 24 25  30  31  48  49  54  55
2  4  8 10 26 28  32  34  50  52  56  58
3  5  9 11 27 29  33  35  51  53  57  59
12 14 18 20 36 38  42  44  60  62  66  68
13 15 19 21 37 39  43  45  61  63  67  69
16 17 22 23 40 41  46  47  64  65  70  71
72 74 78 80 84 86  96  98 102 104 108 110
73 75 79 81 85 87  97  99 103 105 109 111
76 77 82 83 88 89 100 101 106 107 112 113
90 91 92 93 94 95 114 115 116 117 118 119

The (< I , J )&{ of this table corresponds to the Jth occurence
of the Ith unique permutation of the vector in its table of all
possible permutations.

Thanks,
Louis

----------------------------------------------------------------------
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