Multicombinations.jl
An iterator for kcombinations with repetitions, kmulticombinations, kmultisubsets or whatever you want to call them.
Installation
Install this package with Pkg.clone("git://github.com/jlep/Multicombinations.jl")
Usage

multichoose(n, k)
Return the number of multisets of length
k
onn
symbols.Examples
multichoose(3,2)
yields
6

multicombinations(xs, k)
Iterate over every
k
size multisubset of a collectionxs
.Example:
for i in multicombinations([1,2,3],2) @show i end
yields
i => [1,1] i => [1,2] i => [1,3] i => [2,2] i => [2,3] i => [3,3]

integersums(n, k)
Iterate over every nonnegative integer solution of the equation: x_{1} + x_{2} + ... + x_{n} = k.
The order in which the solutions are given corresponds to the order of subsets given by
multicombinations(xs, k)
.Example:
for i in integersums(3,2) @show i end
yields
i => [2,0,0] i => [1,1,0] i => [1,0,1] i => [0,2,0] i => [0,1,1] i => [0,0,2]

is2mc(s)
Convert a solution array given by
integersums(n, k)
to the corresponding multicombination index array.Example:
for i in integersums(3,2) @show is2mc(i) end
yields
is2mc(i) => [1,1] is2mc(i) => [1,2] is2mc(i) => [1,3] is2mc(i) => [2,2] is2mc(i) => [2,3] is2mc(i) => [3,3]