Skip to content

computational-combinatorics/permutation

Repository files navigation

Permutations code bricks for JavaScript.

NPM 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 duo, component, bower, or npm.

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

Example usage:

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 ]