combinations
Generate all possible combinations, which are all the unordered samples of size k, without replacement, from a set of n objects. The number of k-combinations is equal to the binomial coefficient:
Very low memory footprint even if the number of combinations to generate is high. Thank to generators, you can iterate over all possible samples, without creating a very large array.
Installation
$ npm install ml-combinations
Usage
const combinations = require('ml-combinations');
const options = { mode: 'index' };
var gen = combinations(2, 4, options);
for (let combination of gen) {
console.log(combination);
}
console.log([...gen]);
options.mode = 'mask';
gen = combinations(2, 4, options);
console.log([...gen]);
References
Phillip J Chase, `Algorithm 382: Combinations of M out of N Objects [G6]',
Communications of the Association for Computing Machinery 13:6:368 (1970).
To the article
License
MIT