Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

permutation-rank

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

permutation-rank

Ranks and unranks permutations

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

permutation-rank

Ranks and unranks permutations. Based on the following paper:

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

Usage

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 ]

require("permutation-rank").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

require("permutation-rank").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

Credits

(c) 2013 Mikola Lysenko. MIT License

Keywords

FAQs

Package last updated on 26 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc