Usage
:warning: Depending on your environment, the code may require
regeneratorRuntime
to be defined, for instance by importing regenerator-runtime/runtime.
First, require the polyfill at the entry point of your application
await import('regenerator-runtime/runtime.js');
// or
import 'regenerator-runtime/runtime.js';
Then, import the library where needed
const permutation = await import('@combinatorics/permutation');
// or
import * as permutation from '@combinatorics/permutation';
Examples
More examples in the test files.
import {
identity ,
reversed ,
next
} from '@combinatorics/permutation' ;
let sigma = identity( 3 ) ;
sigma ; // [ 0 , 1 , 2 ]
reversed( sigma ) ; // [ 2 , 1 , 0 ]
next( sigma ) ; // [ 0 , 2 , 1 ]
import { permutations } from '@combinatorics/permutation' ;
for ( let tau of permutations( 3 ) ) {
... // yields [ 0 , 1 , 2 ]
// [ 0 , 2 , 1 ]
// [ 1 , 0 , 2 ]
// [ 1 , 2 , 0 ]
// [ 2 , 0 , 1 ]
// [ 2 , 1 , 0 ]
}
import { invert } from '@combinatorics/permutation' ;
invert( [ 0 , 1 , 2 ] ) ; // [ 0 , 1 , 2 ]
invert( [ 0 , 2 , 1 ] ) ; // [ 0 , 2 , 1 ]
invert( [ 1 , 0 , 2 ] ) ; // [ 1 , 0 , 2 ]
invert( [ 1 , 2 , 0 ] ) ; // [ 2 , 0 , 1 ]
invert( [ 2 , 0 , 1 ] ) ; // [ 1 , 2 , 0 ]
invert( [ 2 , 1 , 0 ] ) ; // [ 2 , 1 , 0 ]
import { compose } from '@combinatorics/permutation' ;
compose( "abc" , [ 2 , 0 , 1 ] ) ; // [ "c" , "a" , "b" ]
import { bitreversal } from '@combinatorics/permutation' ;
bitreversal( 8 ) ; // [ 0 , 4 , 2 , 6 , 1 , 5 , 3 , 7 ]