Skip to content

Commit

Permalink
forgot to add Items() to combo with replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan McIntosh authored and Nathan McIntosh committed Jan 11, 2022
1 parent 10bf4f1 commit bac8974
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions combinations_w_replacements.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ func (c *CombinationsWithReplacement[T]) Indices() []int {
return c.inds
}

// Items is how you get the items in this combination. You iterate with `c.Next()`, and
// then get the combination with `c.Items()`. The data in the slice returned will be
// overwritten every iteration. If you need to keep the data from each iteration, be
// sure to make a copy.
func (c *CombinationsWithReplacement[T]) Items() []T {
fill_buffer(c.buffer, c.data, c.inds)
return c.buffer
}

// num_combinations_w_replacement returns (n+k-1)! / (k! * (n-1)!)
func num_combinations_w_replacement(n, k int) *big.Int {
numerator := factorial(int64(n + k - 1))
Expand Down

0 comments on commit bac8974

Please sign in to comment.