Skip to content
generate multiset combinations (n multichoose k)
C++ Python JavaScript C Makefile
Find file
Latest commit 3b8d14e @ekg Merge pull request #2 from outpaddling/master
Replace hard-coded g++ and gcc for portability.
Failed to load latest commit information.
.gitignore minor comment correction
.travis.yml move to npm, improve documentation
LICENSE move to npm, improve documentation
Makefile Replace hard-coded g++ and gcc for portability.
README.md another minor tweak to readme
cli.js move to npm, improve documentation
index.js move to npm, improve documentation
multichoose.c Non-recursive multichoose implementation in C
multichoose.cpp Correct index advancement arithmetic
multichoose.h add headers to multichoose.h for inclusion in larger projects
multichoose.py add headers to multichoose.h for inclusion in larger projects
multipermute.cpp
multipermute.h added citation of Aaron William's paper
multipermute.py multiset permutations, C++ implementation
package.json ++ npm version
test.js require('./') !!!

README.md

multichoose

NPM

Build Status

multiset combinations of k out of n (n multichoose k)

Overview

This library implements an efficient loopless multiset combination generation algorithm which is (approximately) described in "Loopless algorithms for generating permutations, combinations, and other combinatorial configurations." G Ehrlich - Journal of the ACM (JACM), 1973. (Algorithm 7.)

The method generates all multisets that would be generated from taking k elements from a multiset of n. Repeated multisets are possible if the input set contains repeated elements. The number of multiset combinations equals the multinomial coefficient (n multichoose k).

Usage

node.js implementation

Install via

npm install -g multichoose
var multichoose = require('multichoose')
multichoose(2, [1,2,3], console.log)
// [ 1, 1 ]
// [ 1, 2 ]
// [ 1, 3 ]
// [ 2, 2 ]
// [ 2, 3 ]
// [ 3, 3 ]
% multichoose 3 A B C
A A A
A A B
A A C
A B B
A B C
A C C
B B B
B B C
B C C
C C C

multichoose.cpp

Include is a C++ library/program which contains a generic function to generate multisets for vectors of any type of object. You can test out the program using strings input from the command line by typing:

% make

Running the bare executable prints usage information:

% ./multichoose
usage: 
./multichoose <k> <item1> <item2> ... <itemN>  ~ n multichoose k

Example usage:

% ./multichoose 2 a t g c
a a 
a t 
a g 
a c 
t t
t g 
t c 
g g 
g c 
c c

This example lists all the possible unordered genotypes at a given genetic loci of which there are two copies (e.g. chromosomes). In this case k (=2) could be understood as the expected ploidy of the given locus.

(Note that this is not currently built as the default binary for the npm module, which uses cli.js.)

multichoose.py

A python library implementation is also included for those who like to indent their code consistently.

multiset permutations

TODO: These will be factored into a separate module.

Something went wrong with that request. Please try again.