# [R] Permutations

Gabor Grothendieck ggrothendieck at myway.com
Wed Jul 14 18:47:07 CEST 2004

```As Erich points out, there is some question as to
what the original problem really is but lets
assume its as Erich describes.  Then, to get a
random ordered permutation we just get a random
permutation of 12 elements and sort the intra-block
elements like this:

c(apply(matrix(sample(12,12),3),2,sort))

Note that there are 12! = 479,001,600 permutations
of 12 elements and 3!^4 = 1,296 of those
permutations correspond to each ordered
permutation so there are 479,001,600 / 1,296 =
369,600 ordered permutations in all.

Erich Neuwirth <erich.neuwirth <at> univie.ac.at> writes:

:
: Perhaps what you want might better be described as
: ordered partitions?
:
: Is what you want the following:
:
: We study sequences of length 12 and divide them in
: 4 segments
: position 1 2 3, position 4 5 6,
: position 7 8 9, position 10 11 12,
:
: Find all permutation sequences of the numbers 1 to 12
: with the property that all segment sequences
: are monotonically increasing.
:
: I think that produces what you need.
: Since the segments are ordered, you avoid intra-block permutations.
:
: If that is what you want, writing a recursive function should not be
: too hard.
:
:
: > Dear R users,
: > I'm a beginner user of R and I've a problem with permutations that I
: > don't know how to solve. I've 12 elements in blocks of 3 elements and I
: > want only to make permutations inter-blocks (no intra-blocks) (sorry if
: > the terminology is not accurate), something similar to:
: >
: > 1 2 3 | 4 5 6 | 7 8 9 | 10 11 12   ----------1st permutation
: >
: > 1 3 2 | 4 5 6 | 7 8 9 | 10 11 12   NO
: >   -  -
: > 3 2 1 | 4 5 6 | 7 8 9 | 10 11 12   NO
: > -  -  -
: > 1 2 4 | 3 5 6 | 7 8 9 | 10 11 12   YES-----2nd permutation
: >      -    -
: > 4 5 6 | 1 2 3 | 7 8 9 | 10 11 12   YES-----3rd permutation
: > -  -  -   -  -  -
: > 4 5 6 | 2 1 3 | 7 8 9 | 10 11 12   NO
: >           -  -
: > ....
: >
: >  Thanks for your time,
: >
: > Jordi Altirriba
: > Ph D student
: >
: > Hospital Clinic â"Barcelona - Spain
: >
: >
: > MSN Motor. http://motor.msn.es/researchcentre/
: >
: > ______________________________________________
: > R-help <at> stat.math.ethz.ch mailing list
: > https://www.stat.math.ethz.ch/mailman/listinfo/r-help