2.0.0 • Published 7 years ago
@aureooms/js-permutation v2.0.0
js-permutation
Permutations code bricks for JavaScript.
next( reversed( identity( 3 ) ) ) ; // [ 0 , 1 , 2 ]
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 ]