• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D17-Nov-201541 65

.travis.ymlH A D17-Nov-2015119 149

LICENSEH A D17-Nov-20151.1 KiB2217

MakefileH A D17-Nov-2015442 2212

README.mdH A D17-Nov-20152.2 KiB9367

multichoose.cH A D17-Nov-2015945 5442

multichoose.cppH A D17-Nov-20151.9 KiB6726

multichoose.hH A D17-Nov-20152.1 KiB8035

multichoose.pyH A D03-May-20221.9 KiB5644

multipermute.cppH A D17-Nov-20151.9 KiB6725

multipermute.hH A D17-Nov-20153.4 KiB13377

multipermute.pyH A D03-May-20222.6 KiB9985

package.jsonH A D17-Nov-2015723 3534

README.md

1# multichoose
2
3[![NPM](https://nodei.co/npm/multichoose.png?global=true)](https://nodei.co/npm/multichoose/)
4
5[![Build Status](https://travis-ci.org/ekg/multichoose.svg)](https://travis-ci.org/ekg/multichoose)
6
7multiset combinations of k out of n (n multichoose k)
8
9## Overview
10
11This 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.)
12
13The 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).
14
15## Usage
16
17### node.js implementation
18
19Install via
20
21``` bash
22npm install -g multichoose
23```
24
25``` js
26var multichoose = require('multichoose')
27multichoose(2, [1,2,3], console.log)
28// [ 1, 1 ]
29// [ 1, 2 ]
30// [ 1, 3 ]
31// [ 2, 2 ]
32// [ 2, 3 ]
33// [ 3, 3 ]
34```
35
36``` bash
37% multichoose 3 A B C
38A A A
39A A B
40A A C
41A B B
42A B C
43A C C
44B B B
45B B C
46B C C
47C C C
48```
49
50### multichoose.cpp
51
52Include 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:
53
54``` bash
55% make
56```
57
58Running the bare executable prints usage information:
59
60``` bash
61% ./multichoose
62usage:
63./multichoose <k> <item1> <item2> ... <itemN>  ~ n multichoose k
64```
65
66Example usage:
67
68``` bash
69% ./multichoose 2 a t g c
70a a
71a t
72a g
73a c
74t t
75t g
76t c
77g g
78g c
79c c
80```
81
82This 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.
83
84(Note that this is not currently built as the default binary for the npm module, which uses cli.js.)
85
86### multichoose.py
87
88A python library implementation is also included for those who like to indent their code consistently.
89
90## multiset permutations
91
92TODO: These will be factored into a separate module.
93