Combination Class |
Namespace: Kaos.Combinatorics
public class Combination : IComparable, IEnumerable, IComparable<Combination>, IEquatable<Combination>, IEnumerable<int>
The Combination type exposes the following members.
Name | Description | |
---|---|---|
Combination |
Initializes an empty combination instance.
| |
Combination(Int32) |
Initializes a new combination of Rank 0 with the supplied number of elements.
| |
Combination(Combination) |
Initializes a new instance that is copied from the supplied combination.
| |
Combination(Int32, Int32) |
Initializes a new combination of Rank 0
with the supplied number of picks from the supplied number of choices.
| |
Combination(Int32, Int32) |
Initializes a new combination from elements supplied in source
picked from the supplied number of choices.
| |
Combination(Int32, Int32, Int64) |
Initializes a new combination of the supplied rank
with the supplied number of picks from the supplied number of choices.
|
Name | Description | |
---|---|---|
Choices |
The available number of integers to choose from.
| |
Item |
Get a element of the Combination at the supplied column.
| |
Picks |
Number of elements in the Combination.
| |
Rank |
Row index in the ordered Combination table.
| |
RowCount |
Count of distinct sequences in the Combination table.
|
Name | Description | |
---|---|---|
CompareTo(Object) | Compare two Combinations. | |
CompareTo(Combination) | Compare two Combinations. | |
CopyTo |
Copy the entire sequence to the supplied destination.
| |
Equals(Object) |
Indicate whether two Combinations have the same value.
(Overrides ObjectEquals(Object).) | |
Equals(Combination) |
Indicate whether two Combinations have the same value.
| |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetEnumerator | Enumerate all elements of a Combination. | |
GetHashCode | Get the hash oode of the Combination. (Overrides ObjectGetHashCode.) | |
GetRows |
Iterate thru all rows of the Combination table
for every value of Rank ascending.
| |
GetRowsForAllPicks |
Iterate thru all rows of all Combination tables for every
pick in the range (1..Picks).
| |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
PermuteT |
Apply a Combination sequence to rearrange the supplied list or array.
| |
ToString |
Provide a readable form of the Combination sequence.
(Overrides ObjectToString.) |
Name | Description | |
---|---|---|
Equality | Indicate whether 2 Combinations are equal. | |
GreaterThan | Indicate whether the left Combination is greater than
the right Combination. | |
GreaterThanOrEqual | Indicate whether the left Combination is greater than
or equal to the right Combination. | |
Inequality | Indicate whether 2 Combinations are not equal. | |
LessThan | Indicate whether the left Combination is less than
the right Combination. | |
LessThanOrEqual | Indicate whether the left Combination is less than or equal
to the right Combination. |
The defining variables of a combination are n which is the number of possible choices and k which is the number of distinct picks from those choices. When k is less than n, this is a k-combination also known as a pick-combination. Combinations are contrasted to multicombinations where the values in the sequence may repeat.
The Combination class produces k-combinations with ascending elements. While sequence order of the elements is not a general requirement of combinations, producing an ascending sequence allows ranking the sequences into an ordered table.
Use the Picks property to get the number of elements (k) of a Combination taken from a possible number of Choices (n). Use the RowCount property to get the number of distinct possible Combination sequences. Use the indexer to get a specified element of the sequence. Use the default enumerator to iterate thru the elements of a Combination. Use the Permute method to pick objects from a supplied array of choices based on the current sequence.
Use the Rank property to get or set the row index in a lexicographically ordered Combination table of all possible sequences in an ascending order. Use GetRows to iterate thru all possible sequences of the Combination ordered by Rank. Use GetRowsForAllPicks to iterate thru every table of all picks in the range (1..Picks).
The default appearance of a Combination row is a list of integers (starting at 0) enclosed in braces. The appearance may be tailored 3 ways:
For more information about k-combinations, see:
https://en.wikipedia.org/wiki/Combination
Iterating thru new Combination (6, 3).GetRows() produces:
{ 0, 1, 2 }
{ 0, 1, 3 }
{ 0, 1, 4 }
{ 0, 1, 5 }
{ 0, 2, 3 }
{ 0, 2, 4 }
{ 0, 2, 5 }
{ 0, 3, 4 }
{ 0, 3, 5 }
{ 0, 4, 5 }
{ 1, 2, 3 }
{ 1, 2, 4 }
{ 1, 2, 5 }
{ 1, 3, 4 }
{ 1, 3, 5 }
{ 1, 4, 5 }
{ 2, 3, 4 }
{ 2, 3, 5 }
{ 2, 4, 5 }
{ 3, 4, 5 }