The OpenD Programming Language

combinationsRepeat

Lazily computes all k-combinations of r with repetitions. A k-combination with repetitions, or k-multicombination, or multisubset of size k from a set S is given by a sequence of k not necessarily distinct elements of S, where order is not taken into account. Imagine this as the cartesianPower filtered for only ordered items.

While generating a new combination with repeats is in O(k), the number of combinations with repeats is binomial(n + k - 1, k).

  1. CombinationsRepeat!T combinationsRepeat(size_t n, size_t k)
    @safe pure nothrow
    combinationsRepeat
    (
    T = uint
    )
    (
    size_t n
    ,
    size_t k = 1
    )
    if (
    T.sizeof <= size_t.sizeof
    )
  2. IndexedRoR!(CombinationsRepeat!T, Range) combinationsRepeat(Range r, size_t k)

Parameters

n size_t

number of elements (|r|)

k size_t

number of combinations

Return Value

Type: CombinationsRepeat!T

Forward range, which yields the k-multicombinations items

See Also

Meta