This is a `playground`

to test code. It runs a full `Node.js`

environment and already has all of `npm`

’s 400,000 packages pre-installed, including `permutation-rank`

with all `npm`

packages installed. **Try it out**:

var permutationRank = require("permutation-rank")

- all documents on RunKit are public
`require()`

any package directly from npm- use arrow functions, classes, template strings, and most of ES6
`await`

any promise instead of using callbacks (example)- create your own embedded
**node.js**snippets

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

Ranks and unranks permutations. Based on the following paper:

W. Myrvold, F. Ruskey. (2000) "Ranking and Unranking Permutations in Linear Time". Information Processing Letters.

First install using npm:

```
npm install permutation-rank
```

Then you can use it like this:

```
var prank = require("permutation-rank")
var perm = [0,3,1,2]
var r = prank.rank(perm)
console.log("r = ", r)
var u = prank.unrank(perm.length, r)
console.log("u = ", u)
//Prints:
// r = 15
// u = [ 0, 3, 1, 2 ]
```

`prank.rank(permutation)`

Computes an integer representing the colexicographic rank of the permutation

`permutation`

is an array encoding some permutation

**Returns** An integer representing the ranked encoding of the permutation

`prank.unrank(length, rank[, result])`

Computes a permutation from a rank order with the given length

`length`

is the length of the permuation`rank`

is the index of the permutation`result`

is an optional argument which stores the result of the inversion

**Returns** The permutation at the given rank

(c) 2013 Mikola Lysenko. MIT License

- package on npmhttps://npmjs.com/package/permutation-rank
- licenseMIT

RunKit is a free, in-browser JavaScript dev environment for prototyping **Node.js** code, with every **npm** package installed. Sign up to share your code.

Sign Up for Free