# Permutations of an array - APL

In Dyalog APL, there's a predefined function in the `dfns`

library to generate a matrix of permutations for a list of the numbers from 1 to n.

I want to create the same functionality, except that it should work for any array, not just a range 1 to n, in APL NARS2000.

How do I implement that?

## 1 answer

I assume the built-in definition you're referring to is pmat. That illustrates how to solve your problem near the bottom. The idea is simply if σ is a permutation of length N and A is an array of length N, then A[σ] is A permuted by σ. This leads to a definition like:

```
permute←{⍵[pmat⊃⍴⍵]}
```

with

```
permute 'abc'
```

producing

```
abc
acb
bac
bca
cab
cba
```

(The example in the documentation uses `{⍵[pmat⍴⍵]}`

but this seemed to lead to rank errors when I tried it in online interpreters using one of the definitions of `pmat`

listed on that page.)

#### 2 comments

I am trying to do this in NARS2000 where pmat is not built in, so `{⍵[pmat ⍴⍵]}`

doesn't exactly work.

The linked page provides several implementations of `pmat`

.

## 0 comments