lib/comb-set.js
function ( n, k ) {
            if ( ! n || ( n < k ) )
                throw new RangeError( 'check input values' )
                ;
            // buffer for generating combinations
            const buff = balloc( n, 0 )
                // colex recursive generator
                , colex_gen = function *( n, k ) {
                    if ( n === 0 ) yield buff;
                    else {
                        if ( k < n ) {
                            buff[ n - 1 ] = 0;
                            yield* colex_gen( n - 1, k );
                        }
                        if ( k > 0 ) {
                            buff[ n - 1 ] = 1;
                            yield* colex_gen( n - 1, k - 1 );
                        }
                    }
                }
                // generating colex order for k <= n/2.
                , colex_gen_2 = function *( n, k ) {
                    if ( k === 0 ) yield buff;
                    else {
                        if ( k < n ) {
                            buff[ n - 1 ] = 0;
                            yield* colex_gen_2( n - 1, k );
                        }
                        buff[ n - 1 ] = 1;
                        yield* colex_gen_2( n - 1, k - 1);
                        buff[ n - 1 ] = 0;
                    }
                }
                ;
            return ( k > n / 2 ) ?
                colex_gen( n , k ) :
                colex_gen_2( n, k )
                ;
        }
function ( n, k ) {
            if ( ! n || ( n < k ) )
                throw new RangeError( 'check input values' )
                ;
            // buffer for generating combinations
            const buff = balloc( n, 0 )
                // colex recursive generator
                , colex_gen = function *( n, k ) {
                    if ( n === 0 ) yield buff;
                    else {
                        if ( k < n ) {
                            buff[ n - 1 ] = 0;
                            yield* colex_gen( n - 1, k );
                        }
                        if ( k > 0 ) {
                            buff[ n - 1 ] = 1;
                            yield* colex_gen( n - 1, k - 1 );
                        }
                    }
                }
                // generating colex order for k <= n/2.
                , colex_gen_2 = function *( n, k ) {
                    if ( k === 0 ) yield buff;
                    else {
                        if ( k < n ) {
                            buff[ n - 1 ] = 0;
                            yield* colex_gen_2( n - 1, k );
                        }
                        buff[ n - 1 ] = 1;
                        yield* colex_gen_2( n - 1, k - 1);
                        buff[ n - 1 ] = 0;
                    }
                }
                ;
            return ( k > n / 2 ) ?
                colex_gen( n , k ) :
                colex_gen_2( n, k )
                ;
        }
function ( n , k ) { if ( ! n || ( n < k ) ) throw new RangeError ( 'check input values' ) ; // buffer for generating combinations const buff = balloc ( n , 0 ) // colex recursive generator , colex_gen = function * ( n , k ) { if ( n === 0 ) yield buff ; else { if ( k < n ) { buff [ n - 1 ] = 0 ; yield * colex_gen ( n - 1 , k ) ; } if ( k > 0 ) { buff [ n - 1 ] = 1 ; yield * colex_gen ( n - 1 , k - 1 ) ; } } } // generating colex order for k <= n/2. , colex_gen_2 = function * ( n , k ) { if ( k === 0 ) yield buff ; else { if ( k < n ) { buff [ n - 1 ] = 0 ; yield * colex_gen_2 ( n - 1 , k ) ; } buff [ n - 1 ] = 1 ; yield * colex_gen_2 ( n - 1 , k - 1 ) ; buff [ n - 1 ] = 0 ; } } ; return ( k > n / 2 ) ? colex_gen ( n , k ) : colex_gen_2 ( n , k ) ; }
CAT generator for combinations without replacement
CAT generator for combinations without replacement