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.
Requires regeneratorRuntime
to be defined, see
babel docs.
jspm install github:aureooms/js-permutation
# or
jspm install npm:aureooms-js-permutation
No install step needed for duo!
component install aureooms/js-permutation
bower install aureooms-js-permutation
ender add aureooms-js-permutation
jam install aureooms-js-permutation
spm install aureooms-js-permutation --save
npm install aureooms-js-permutation --save
let permutation = require( "github:aureooms/js-permutation" ) ;
// or
import permutation from 'aureooms-js-permutation' ;
let permutation = require( "aureooms/js-permutation" ) ;
let permutation = require( "aureooms-js-permutation" ) ;
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.
require( [ "aureooms-js-permutation" ] , function ( permutation ) { ... } ) ;
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 ]