Skip to content

Rewrite the Chase's Twiddle algorithm that returns all combinations of `k` out of `n` objects

License

Notifications You must be signed in to change notification settings

lamphamsy/node-twiddle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-twiddle

Rewrite in NodeJS the Chase's Twiddle algorithm that returns all combinations of m out of n objects.

The C implementation can be found here.

API

Import library

const NodeTwiddle = require('node-twiddle');

Initialization

const twiddle = new NodeTwiddle(n, m);

where n is total number of objects, m is number of objects in each combination.

Generate and return all combinations

twiddle.genAllCombs(input)

where input is an optional parameter for array of n objects. Hence, output is all combination of m out of the n objects. If the input is not given, output is an array of all sequences of 0's and 1's containing m 1's.

Iterate each combination

Initialize parameters for iterating

const params = twiddle.init(input)

The input parameter is optional as described above.

The 1st combination is params.res. Each next combination is iterated via

twiddle.iterate(params)

If it returns undefined, the iteration ends.

About

Rewrite the Chase's Twiddle algorithm that returns all combinations of `k` out of `n` objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published