Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Coeff ¶
Coeff calculates the binomial coefficient n choose k and returns it as an int. Coeff panics if the calculation would overflow.
func CoeffUint64 ¶
CoeffUint64 returns the binomial coefficient n choose k as a uint64. CoeffUint64 panics if the calculation would overflow the uint64.
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator iterates over all ways of choosing k elements from 0, ..., n-1 in lexicographic order.
func NewIterator ¶
NewIterator returns a new Iterator to iterate over all subsets of k distinct elements from 0, ..., n-1 in lexicographic order.
type PartitionIterator ¶
type PartitionIterator struct {
// contains filtered or unexported fields
}
PartitionIterator iterates over all partitions of the set {0, ..., n-1}. The partitions are generated in lexicographic order of their restricted growth strings. It is safe to modify the output of .Value().
func NewPartitionIterator ¶
func NewPartitionIterator(n int) *PartitionIterator
TODO Handle n = 0 NewPartitionIterator returns a *PartitionIterator which iterates over all partitions of the set {0, ..., n-1}. The partitions are generated in lexicographic order of their restricted growth sequences.
func (*PartitionIterator) Next ¶
func (pi *PartitionIterator) Next() bool
Next tries to advance pi to the next partition, returning true if there is one and false if there isn't.
func (PartitionIterator) Value ¶
func (pi PartitionIterator) Value() [][]int
Value returns the current partition. It is safe to modify the output.