Forms all possible permutations of the integers 1…*n* (J.W. McNicol & R.W. Payne).

### Option

`SORT` = string token |
Whether or not to sort the permutations (`no` , `yes` ); default `no` |
---|

### Parameters

`NVALUES` = scalars |
Specifies the final number, n, in the sequence of integers 1…n to be permuted |
---|---|

`PERMUTATIONS` = pointers |
Pointer to a set of variates of length `NVALUES` storing the permutations |

### Description

`PERMUTE`

forms all the permutations of the integers 1 up to the value *n* specified by the `NVALUES`

parameter. The permutations are saved, as a set of variates each of length `NVALUES`

, in a pointer supplied by the `PERMUTATIONS`

parameter. By default, the permutations will occur in an arbitrary order, but option `SORT`

can be set to `yes`

to sort them into the standard (lexicographic) order.

Option: `SORT`

.

Parameters: `NVALUES`

, `PERMUTATIONS`

.

### Method

The procedure uses the standard Genstat manipulation directives, `CALCULATE`

, `EQUATE`

etc.

### See also

Directive: `SETALLOCATIONS`

.

Procedures: `APERMTEST`

, `CHIPERMTEST`

, `RPERMTEST`

.

Commands for: Calculations and manipulation.

### Example

CAPTION 'PERMUTE example',\ 'Form all permutations of the numbers 1-4.'; STYLE=meta,plain PERMUTE [SORT=yes] 4; P PRINT [IPRINT=*] P[]; FIELD=2; DECIMALS=0