Skip to content

computational-combinatorics/permutation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

Can be managed through bower, component, 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" ]