Re: [Jprogramming] permutations

2023-03-16 Thread Elijah Stone
There is only one cycle, yes. The point of the example was to demonstrate pathology with a very long cycle. On Fri, 17 Mar 2023, Jan-Pieter Jacobs wrote: Probably it's just something going over my head, but how do these permutations have more than one cycle? #@C. _1 1 |."0 _ i. 128 1 1 C.

Re: [Jprogramming] permutations

2023-03-16 Thread Elijah Stone
Oh, nice! I tried <./{~^:(<2>.@^.#p)p, but that loses information; your solution retains it in m. On Thu, 16 Mar 2023, Marshall Lochbaum wrote: Interesting problem! I think this works: for starting permutation p, keep two lists. At step i, - l is {~^:i p, that is, the index 2^i steps further

Re: [Jprogramming] permutations

2023-03-16 Thread Jan-Pieter Jacobs
Probably it's just something going over my head, but how do these permutations have more than one cycle? #@C. _1 1 |."0 _ i. 128 1 1 C. y returns boxed cycles in permutation y. What am I missing? Jan-Pieter On Fri, 17 Mar 2023, 01:07 Marshall Lochbaum, wrote: > Interesting problem! I thin

Re: [Jprogramming] permutations

2023-03-16 Thread Marshall Lochbaum
Interesting problem! I think this works: for starting permutation p, keep two lists. At step i, - l is {~^:i p, that is, the index 2^i steps further along the cycle - m is the minimum index among those less than 2^i steps ahead. Initially l is p and m is i.#p . To update, simultaneously replace l

[Jprogramming] permutations

2023-03-16 Thread Elijah Stone
I can characterise the cycles of a permutation with (<.{~)^:_ (this keys each cycle by its lowest element, but any unique key is fine). But although this sometimes has log span (in the length of the longest cycle): # (<.{~)^:(<_) _1|.i.128 8 The worst case is linear span: # (<.{~)^:(<_)

Re: [Jprogramming] Permutations of Hanoi

2021-10-31 Thread Raul Miller
A slight variation: permh=: (- i.) #: i.@! Thanks again, -- Raul On Sun, Oct 31, 2021 at 2:27 PM xash wrote: > > With mixed bases, for e.g. 3: > 3 2 1 #: i. 6 > > An equivalent function of permh is thus: > (>:@i.@- #: i.@!) 3 > > If you want to map arbitrary n to a permutation with unknown

Re: [Jprogramming] Permutations of Hanoi

2021-10-31 Thread Raul Miller
Nice! (I feel like I should have seen that...) Thanks, -- Raul On Sun, Oct 31, 2021 at 2:27 PM xash wrote: > > With mixed bases, for e.g. 3: > 3 2 1 #: i. 6 > > An equivalent function of permh is thus: > (>:@i.@- #: i.@!) 3 > > If you want to map arbitrary n to a permutation with unknown leng

Re: [Jprogramming] Permutations of Hanoi

2021-10-31 Thread xash
With mixed bases, for e.g. 3: 3 2 1 #: i. 6 An equivalent function of permh is thus: (>:@i.@- #: i.@!) 3 If you want to map arbitrary n to a permutation with unknown length, you could use something like this (I love J for things like !^:_1): (#:~ [:>:@i.@-@<.@>: !^:_1)"0 (2+i.4) NB. needs specia

[Jprogramming] Permutations of Hanoi

2021-10-31 Thread Raul Miller
(I really do not know the "right" historical terminology for talking about this, thus the subject line and the odd intro I am using here.) In the Tower of Hanoi puzzle, we move a stack of disks from one tower to another, moving only the top piece. But imagine that we could remove the disks in any

Re: [Jprogramming] Permutations, primes and modular arithmetic

2020-01-29 Thread Jimmy Gauvin
Hi, thanks for all the input, Jimmy PS It seems the sequence 0 6 1 7 2 8 3 9 4 10 5 lost its last element during the editing process (thanks to those who pointed it out). On Wed, Jan 29, 2020 at 4:40 AM Jan-Pieter Jacobs < janpieter.jac...@gmail.com> wrote: > There's two pages in Fifty

Re: [Jprogramming] Permutations, primes and modular arithmetic

2020-01-29 Thread Jan-Pieter Jacobs
There's two pages in Fifty shades of J that might be of interest too: https://code.jsoftware.com/wiki/Fifty_Shades_of_J/Chapter_31 https://code.jsoftware.com/wiki/Fifty_Shades_of_J/Chapter_32 Jan-Pieter On Wed, Jan 29, 2020, 06:20 Devon McCormick wrote: > Has no one mentioned "A." yet? > > On

Re: [Jprogramming] Permutations, primes and modular arithmetic

2020-01-28 Thread Devon McCormick
Has no one mentioned "A." yet? On Tue, Jan 28, 2020 at 10:10 PM Henry Rich wrote: > This is the Chinese Remainder Theorem, no? > > Henry Rich > > On 1/28/2020 9:49 PM, 'Jon Hough' via Programming wrote: > > See Modulo Multiplication Group: > > https://en.wikipedia.org/wiki/Multiplicative_group

Re: [Jprogramming] Permutations, primes and modular arithmetic

2020-01-28 Thread 'Jon Hough' via Programming
I think the CRT is related ( https://en.wikipedia.org/wiki/Chinese_remainder_theorem ) in the sense that it is about modulo arithmetic and congruences, but I am not sure it has much to do with permutations fo the moduli. It states that given some pairwise coprime x1 x2 x3 ... xk, then if N =

Re: [Jprogramming] Permutations, primes and modular arithmetic

2020-01-28 Thread Henry Rich
This is the Chinese Remainder Theorem, no? Henry Rich On 1/28/2020 9:49 PM, 'Jon Hough' via Programming wrote: See Modulo Multiplication Group: https://en.wikipedia.org/wiki/Multiplicative_group_of_integers_modulo_n http://mathworld.wolfram.com/ModuloMultiplicationGroup.html Since 11 is pri

Re: [Jprogramming] Permutations, primes and modular arithmetic

2020-01-28 Thread 'Jon Hough' via Programming
See Modulo Multiplication Group: https://en.wikipedia.org/wiki/Multiplicative_group_of_integers_modulo_n http://mathworld.wolfram.com/ModuloMultiplicationGroup.html Since 11 is prime, its modulo multiplication group has 10 elements (all the numbers from 1 to 10). i.e. multiplying the elements b

Re: [Jprogramming] Permutations, primes and modular arithmetic

2020-01-28 Thread ethiejiesa via Programming
This is a beautiful list! Thank you for sharing. Regarding your 3) and 6) versions with modulo arithmetic, happily, this is a standard result from number theory. You should be able to find the relevant background and theorem itself near the beginning of any introductory Number Theory book. IIRC, m

[Jprogramming] Permutations, primes and modular arithmetic

2020-01-28 Thread Jimmy Gauvin
Hi, I am looking for some reference texts on permutations and modular arithmetic. I recently stumbled on some interesting properties of card shuffles. For example, using a deck of 11 cards labeled 0 through 10 and shuffling them to obtain this layout : 0 6 1 7 2 8 3 9 4 10 There are

Re: [Jprogramming] permutations the slow way

2016-05-02 Thread 'Pascal Jasmin' via Programming
ent: Monday, May 2, 2016 2:47 PM Subject: Re: [Jprogramming] permutations the slow way This, perhaps: ;"1 ({.,"0 1 $:^:(1(] <@; $:^:(1 < #)@-.)"1 0~ 0 1 2 3 Sorry about the goof, earlier. Thanks, -- Raul On Mon, May 2, 2016 at 2:40 PM, Raul Miller wrote: > Thi

Re: [Jprogramming] permutations the slow way

2016-05-02 Thread Raul Miller
;"1)@:((] ,"0 1 $:^:(1 < #)@-.)"1 0~) 0 1 2 3 >> >> but I also struggle with the tree walking approach that is say generated with >> >> (] <@; $:^:(1 < #)@-.)"1 0~ 0 1 2 3 >> >> >> >> - Original Message -

Re: [Jprogramming] permutations the slow way

2016-05-02 Thread Raul Miller
ree walking approach that is say generated with >> >> (] <@; $:^:(1 < #)@-.)"1 0~ 0 1 2 3 >> >> >> >> - Original Message - >> From: Raul Miller >> To: Programming forum >> Sent: Monday, May 2, 2016 1:06 PM >> Su

Re: [Jprogramming] permutations the slow way

2016-05-02 Thread Raul Miller
gt; > ,&.:(<"1)@:((] ,"0 1 $:^:(1 < #)@-.)"1 0~) 0 1 2 3 > > but I also struggle with the tree walking approach that is say generated with > > (] <@; $:^:(1 < #)@-.)"1 0~ 0 1 2 3 > > > > - Original Message - > From: Rau

Re: [Jprogramming] permutations the slow way

2016-05-02 Thread 'Pascal Jasmin' via Programming
-- Original Message - From: Raul Miller To: Programming forum Sent: Monday, May 2, 2016 1:06 PM Subject: Re: [Jprogramming] permutations the slow way This good enough? ;"1 ({.,.>@}.)S:2 (] <@; $:^:(1 < #)@-.)"1 0~ 0 1 2 Or did you have additional constraints? Thank

Re: [Jprogramming] permutations the slow way

2016-05-02 Thread Raul Miller
This good enough? ;"1 ({.,.>@}.)S:2 (] <@; $:^:(1 < #)@-.)"1 0~ 0 1 2 Or did you have additional constraints? Thanks, -- Raul On Mon, May 2, 2016 at 11:21 AM, 'Pascal Jasmin' via Programming wrote: > how might you derive the unboxed permutation list from this tree? > > (] <@; $:^:(1 < #)

[Jprogramming] permutations the slow way

2016-05-02 Thread 'Pascal Jasmin' via Programming
how might you derive the unboxed permutation list from this tree? (] <@; $:^:(1 < #)@-.)"1 0~ 0 1 2 +---+---+---+ |+-+-+-+|+-+-+-+|+-+-+-+| ||0|+-+-+|+-+-+|||1|+-+-+|+-+-+|||2|+-+-+|+-+-+|| || ||1|2|||2|1 ||0|2|||2|0 ||0|1|||1|0

Re: [Jprogramming] permutations without reverses

2015-08-21 Thread 'Pascal Jasmin' via Programming
Nice, thank you. - Original Message - From: R.E. Boss To: programm...@jsoftware.com Cc: Sent: Friday, August 21, 2015 2:45 PM Subject: Re: [Jprogramming] permutations without reverses ts'(#~({.<{:)"1)(i.@!A.i.)8' 0.029197332 9048960 R.E. Boss >

Re: [Jprogramming] permutations without reverses

2015-08-21 Thread R.E. Boss
ijdag 21 augustus 2015 19:36 > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] permutations without reverses > > A version that compares every element to the whole list (so far) to filter out > is innefficient even for perm 8 > > reduce =: 1 : '<"_

Re: [Jprogramming] permutations without reverses

2015-08-21 Thread 'Pascal Jasmin' via Programming
om: 'Pascal Jasmin' via Programming To: Programming Forum Cc: Sent: Friday, August 21, 2015 1:10 PM Subject: [Jprogramming] permutations without reverses for 3, removing the "reverse duplicates" of permutations is as easy as taking the top half (i.@! A. i.) 3 0 1 2 0 2 1

[Jprogramming] permutations without reverses

2015-08-21 Thread 'Pascal Jasmin' via Programming
for 3, removing the "reverse duplicates" of permutations is as easy as taking the top half (i.@! A. i.) 3 0 1 2 0 2 1 1 0 2 1 2 0 2 0 1 2 1 0 last (5) is reverse of 0. 4 is reverse of 2, and 3 reverse of 1 Is there a function for producing permutations without their reverse included?

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-05-03 Thread R.E. Boss
tware.com] On Behalf Of R.E. Boss > Sent: zondag 26 april 2015 9:32 > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Permutations with repeats (combinations?) > > comb=: 4 : 0 > k=. i.>:d=.y-x > z=. (d$ for. i.x do. z=. k ,.&.> ,&.>/\.

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-28 Thread 'Pascal Jasmin' via Programming
]' 2 3+codeinsert 1 2 3 2+3+1 2 3 (2;3)+codeinsert 1 2 3 2+3+1 2 3 (2 1 4; 3)+codeinsert 1 2 3 2 1 4+3+1 2 3 It avoids the boxing, though I doubt its practical for lengthy data. - Original Message - From: Jose Mario Quintana To: Programming foru

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-28 Thread Jose Mario Quintana
mp;.>)/)(>@:) > reduce =: 1 : '<"_1@[ ([: u boxscan ,) <@:]' > > > The list has brought this up before, but is a foreign to do this something > easy and worthwhile? > > > > - Original Message - > From: Jose Mario Quintana > To: Progr

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-27 Thread 'Pascal Jasmin' via Programming
inal Message - From: Jose Mario Quintana To: Programming forum Cc: Sent: Monday, April 27, 2015 7:45 PM Subject: Re: [Jprogramming] Permutations with repeats (combinations?) Right, this is because "I did not make any effort to simplify or to try to optimize the tacit verbs" The tool

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-27 Thread Jose Mario Quintana
d side of ^: > > combT =: ([: ; ([ ; [: i.@>: -~) ((1 {:: [) ,.&.> [: ,&.>/\. > >:&.>@:])^:(0 {:: [) ( > 100 timespacex&> ' 2 combT 5' ; ' 2 combt 5' > 1.91616e_5 5888 > 3.6608e_5 9088 > > > 100 timespacex&> '

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread 'Pascal Jasmin' via Programming
0.0584915 5.03404e7 0.0580249 3.38226e7 - Original Message - From: Jose Mario Quintana To: Programming forum Cc: Sent: Sunday, April 26, 2015 9:55 PM Subject: Re: [Jprogramming] Permutations with repeats (combinations?) Tacit vs. explicit seems to be a never-ending controversy. May as

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread Jose Mario Quintana
re equivalence, but > there > is a J > > feature I have not seen before > > > >$ every ( [ ,"1"1 _1 ] {"1"_ 1 [ -.~"1 i.@(+&({:@$)))L:0/ |. (] > <@comb"0 +/\) > > |.#/.~ 1 1 2 3 3 > > 10 3 1 5 > > > > > >

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread R.E. Boss
...@forums.jsoftware.com] On Behalf Of 'Pascal Jasmin' via > Programming > Sent: zondag 26 april 2015 17:19 > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Permutations with repeats (combinations?) > > Nice, > > I find this easy to follow as there is

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread Henry Rich
(i. 3 2 2) +"1"2 i. 2 2 0 2 4 6 4 6 8 10 8 10 12 14 (i. 3 2 2) +"1 i. 2 2 |length error | (i.3 2 2)+"1 i.2 2 Henry Rich On 4/26/2015 11:19 AM, 'Pascal Jasmin' via Programming wrote: I understand that v"1"2 -: v"1 in all cases?... but not necessarily v"1"_1

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread 'Pascal Jasmin' via Programming
quot;1"_1 - Original Message - From: R.E. Boss To: programm...@jsoftware.com Cc: Sent: Sunday, April 26, 2015 3:31 AM Subject: Re: [Jprogramming] Permutations with repeats (combinations?) comb=: 4 : 0 k=. i.>:d=.y-x z=. (d$ ,&.>/\. >:&.> z end. ; z ) cmbcomb=:

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread R.E. Boss
6' > 3.8703475 3.2212362e9 > > > R.E. Boss > > (Add your info to > http://www.jsoftware.com/jwiki/Community/Demographics ) > > > > -Original Message- > > From: programming-boun...@forums.jsoftware.com > [mailto:programming- >

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread R.E. Boss
5 10:49 > To: Programming forum > Subject: Re: [Jprogramming] Permutations with repeats (combinations?) > > I cannot reproduce your result. > > I get this: > comb=: 4 : 0 > k=. i.>:d=.y-x > z=. (d$ for. i.x do. z=. k ,.&.> ,&.>/\. >:&.> z end. >

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread Raul Miller
mming- >> boun...@forums.jsoftware.com] On Behalf Of Raul Miller >> Sent: zondag 26 april 2015 3:22 >> To: Programming forum >> Subject: Re: [Jprogramming] Permutations with repeats (combinations?) >> >> That's an error on my part. >> >> It' not

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread R.E. Boss
--Original Message- > From: programming-boun...@forums.jsoftware.com [mailto:programming- > boun...@forums.jsoftware.com] On Behalf Of R.E. Boss > Sent: zondag 26 april 2015 8:59 > To: programm...@jsoftware.com > Subject: Re: [Jprogramming] Permutations with repeats (combinations?) &

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-26 Thread R.E. Boss
Sent: zondag 26 april 2015 3:22 > To: Programming forum > Subject: Re: [Jprogramming] Permutations with repeats (combinations?) > > That's an error on my part. > > It' not unique to boxed data, you can see the same flaw with: > > peermm 'ababc' >

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-25 Thread Raul Miller
rm2 1 2 ; 1 2 ; 3 ;3 ; 3 >> 3 3 1 2 1 2 3 >> 3 3 1 2 3 1 2 >> 3 3 3 1 2 1 2 >> 3 1 2 3 1 2 3 >> 3 1 2 3 3 1 2 >> 3 1 2 1 2 3 3 >> 1 2 3 3 1 2 3 >> 1 2 3 3 3 1 2 >> 1 2 3 1 2 3 3 >> 1 2 1 2 3 3 3 >> >> >> >> >> >> >>

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-25 Thread 'Pascal Jasmin' via Programming
this has wrong results peermm 1 1 ; 2 2 ; 1 1 ; 2 2 ;3 - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Saturday, April 25, 2015 8:24 PM Subject: Re: [Jprogramming] Permutations with repeats (combinations?) What problem does it have with boxed data? (It worked

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-25 Thread Raul Miller
> > > > > > - Original Message - > From: Raul Miller > To: Programming forum > Cc: > Sent: Saturday, April 25, 2015 2:02 PM > Subject: Re: [Jprogramming] Permutations with repeats (combinations?) > > My first attempt at implementing like that ran into a problem

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-25 Thread 'Pascal Jasmin' via Programming
2 1 2 3 3 3 - Original Message - From: Raul Miller To: Programming forum Cc: Sent: Saturday, April 25, 2015 2:02 PM Subject: Re: [Jprogramming] Permutations with repeats (combinations?) My first attempt at implementing like that ran into a problem with mix-matched types in r for

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-25 Thread Raul Miller
My first attempt at implementing like that ran into a problem with mix-matched types in r for some cases, so I reworked the thing to support arguments of any type: comb=: 4 : 0 k=. i.>:d=.y-x z=. (d$ ,&.>/\. >:&.> z end. ; z ) peermm=:3 :0 arg=. (/: #@>) arg m=. (i.@! A. i.)n1 for_d.n1}.

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-25 Thread Roger Hui
The peermm function can be made faster by doing the actual permutations of those cells of wrote: > On Fri, Apr 24, 2015 at 7:03 PM, Roger Hui > wrote: > > The details of implementing this algorithm are left as an exercise for > the > > reader. :-) > > Do I qualify as a reader? > > comb=: 4 : 0 >

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-25 Thread 'Pascal Jasmin' via Programming
xtras=. ; }. each To: Programming forum Cc: Sent: Saturday, April 25, 2015 1:46 AM Subject: Re: [Jprogramming] Permutations with repeats (combinations?) On Fri, Apr 24, 2015 at 7:03 PM, Roger Hui wrote: > The details of implementing this algorithm are left as an exercise for the > reader.

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-24 Thread Roger Hui
V. good. On Fri, Apr 24, 2015 at 10:46 PM, Raul Miller wrote: > On Fri, Apr 24, 2015 at 7:03 PM, Roger Hui > wrote: > > The details of implementing this algorithm are left as an exercise for > the > > reader. :-) > > Do I qualify as a reader? > > comb=: 4 : 0 > k=. i.>:d=.y-x > z=. (d$ for

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-24 Thread Raul Miller
On Fri, Apr 24, 2015 at 7:03 PM, Roger Hui wrote: > The details of implementing this algorithm are left as an exercise for the > reader. :-) Do I qualify as a reader? comb=: 4 : 0 k=. i.>:d=.y-x z=. (d$ ,&.>/\. >:&.> z end. ; z ) peermm=:3 :0 r=.i.1 0 for_d.d n=.i.(#s)+{:$r e=.n

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-24 Thread Michal Wallace
Here's a recursive implementation. tree =: ({.,<@$:@;@}.)"1@(({.;}.)S:0,.1[\.])^:(0<#)@( wrote: > archive or wiki did not help, but perhaps I searched wrong > > perm =: i.@! A. i. > > ~.@({~ [: perm #) 1 1 2 2 > 1 1 2 2 > 1 2 1 2 > 1 2 2 1 > 2 1 1 2 > 2 1 2 1 > 2 2 1 1 > > while that is the ans

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-24 Thread 'Pascal Jasmin' via Programming
end. p =. ~. o end. ) - Original Message - From: 'Pascal Jasmin' via Programming To: "programm...@jsoftware.com" Cc: Sent: Friday, April 24, 2015 7:54 PM Subject: Re: [Jprogramming] Permutations with repeats (combinations?) I haven't quite used all of these

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-24 Thread 'Pascal Jasmin' via Programming
2 2 7 7 8 8 9 9 9 9 9 9 ' 0.54311 9.28059e7 - Original Message - From: Roger Hui To: Programming forum Cc: Sent: Friday, April 24, 2015 7:03 PM Subject: Re: [Jprogramming] Permutations with repeats (combinations?) The "secret" is to avoid generating duplicates which are t

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-24 Thread Roger Hui
The "secret" is to avoid generating duplicates which are then removed. Partition the argument into a collection of like elements: :d=.y-x z=. (d$ ,&.>/\. >:&.> z end. ; z ) (#s) comb (#s)+{:$m 0 1 0 2 0 3 1 2 1 3 2 3 From these column indices generate the z: 0 1 2 2 0 1 2 2 1 0 0

Re: [Jprogramming] Permutations with repeats (combinations?)

2015-04-24 Thread Michael Dykman
My take: d=: 1 1 2 2 f=: ~.@: (] {~ (i.@! A. i.)@#) f d 1 1 2 2 1 2 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 2 1 1 On Fri, Apr 24, 2015 at 4:00 PM, 'Pascal Jasmin' via Programming < programm...@jsoftware.com> wrote: > archive or wiki did not help, but perhaps I searched wrong > > perm =: i.@! A

[Jprogramming] Permutations with repeats (combinations?)

2015-04-24 Thread 'Pascal Jasmin' via Programming
archive or wiki did not help, but perhaps I searched wrong perm =: i.@! A. i. ~.@({~ [: perm #) 1 1 2 2 1 1 2 2 1 2 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 2 1 1 while that is the answer I want, and is short and elegant, it grows very innefficient as the length of the argument grows even if the