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 <
[email protected]> 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 answer I want, and is short and elegant, it grows very
> innefficient as the length of the argument grows even if the answer is a
> short list.
>
> Is there an algorithm that can produce these "permutations with repeats"
> without the intermediate full permutation list?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
- michael dykman
- [email protected]
May the Source be with you.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm