Skip to content

computational-combinatorics/permutation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Permutations code bricks for JavaScript.

next( reversed( identity( 3 ) ) ) ; // [ 0 , 1 , 2 ]

License NPM version Bower version Build Status Coverage Status Dependencies Status devDependencies Status Code Climate NPM downloads per month GitHub issues Inline docs

Can be managed through jspm, duo, component, bower, ender, jam, spm, and npm.

Caveat

Requires regeneratorRuntime to be defined, see babel docs.

Install

jspm

jspm install github:aureooms/js-permutation
# or
jspm install npm:@aureooms/js-permutation

duo

No install step needed for duo!

component

component install aureooms/js-permutation

bower

bower install @aureooms/js-permutation

ender

ender add @aureooms/js-permutation

jam

jam install @aureooms/js-permutation

spm

spm install @aureooms/js-permutation --save

npm

npm install @aureooms/js-permutation --save

Require

jspm

let permutation = require( "github:aureooms/js-permutation" ) ;
// or
import permutation from '@aureooms/js-permutation' ;

duo

let permutation = require( "aureooms/js-permutation" ) ;

component, ender, spm, npm

let permutation = require( "@aureooms/js-permutation" ) ;

bower

The script tag exposes the global variable permutation.

<script src="bower_components/@aureooms/js-permutation/js/dist/permutation.min.js"></script>

Alternatively, you can use any tool mentioned here.

jam

require( [ "@aureooms/js-permutation" ] , function ( permutation ) { ... } ) ;

Use

let sigma = permutation.identity( 3 ) ;

sigma ; // [ 0 , 1 , 2 ]

permutation.reversed( sigma ) ; // [ 2 , 1 , 0 ]

permutation.next( sigma ) ; // [ 0 , 2 , 1 ]

for ( let tau of permutation.permutations( 3 ) ) {

	... // yields [ 0 , 1 , 2 ]
	    //        [ 0 , 2 , 1 ]
	    //        [ 1 , 0 , 2 ]
	    //        [ 1 , 2 , 0 ]
	    //        [ 2 , 0 , 1 ]
	    //        [ 2 , 1 , 0 ]

}

permutation.invert( [ 0 , 1 , 2 ] ) ; // [ 0 , 1 , 2 ]
permutation.invert( [ 0 , 2 , 1 ] ) ; // [ 0 , 2 , 1 ]
permutation.invert( [ 1 , 0 , 2 ] ) ; // [ 1 , 0 , 2 ]
permutation.invert( [ 1 , 2 , 0 ] ) ; // [ 2 , 0 , 1 ]
permutation.invert( [ 2 , 0 , 1 ] ) ; // [ 1 , 2 , 0 ]
permutation.invert( [ 2 , 1 , 0 ] ) ; // [ 2 , 1 , 0 ]

permutation.compose( "abc" , [ 2 , 0 , 1 ] ) ; // [ "c" , "a" , "b" ]

permutation.bitreversal( 8 ) ; // [ 0 , 4 , 2 , 6 , 1 , 5 , 3 , 7 ]