Permutations code bricks for JavaScript.
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" ]