Click or drag to resize

Combination Class

Represents an ascending sequence of distinct picks from a supplied range.
Inheritance Hierarchy
SystemObject
  Kaos.CombinatoricsCombination

Namespace:  Kaos.Combinatorics
Assembly:  KaosCombinatorics (in KaosCombinatorics.dll) Version: 6.0.0.0
Syntax
C#
public class Combination : IComparable, 
	IEnumerable, IComparable<Combination>, IEquatable<Combination>, 
	IEnumerable<int>

The Combination type exposes the following members.

Constructors
  NameDescription
Public methodCombination
Initializes an empty combination instance.
Public methodCombination(Int32)
Initializes a new combination of Rank 0 with the supplied number of elements.
Public methodCombination(Combination)
Initializes a new instance that is copied from the supplied combination.
Public methodCode exampleCombination(Int32, Int32)
Initializes a new combination of Rank 0 with the supplied number of picks from the supplied number of choices.
Public methodCode exampleCombination(Int32, Int32)
Initializes a new combination from elements supplied in source picked from the supplied number of choices.
Public methodCode exampleCombination(Int32, Int32, Int64)
Initializes a new combination of the supplied rank with the supplied number of picks from the supplied number of choices.
Top
Properties
  NameDescription
Public propertyChoices
The available number of integers to choose from.
Public propertyCode exampleItem
Get a element of the Combination at the supplied column.
Public propertyPicks
Number of elements in the Combination.
Public propertyCode exampleRank
Row index in the ordered Combination table.
Public propertyRowCount
Count of distinct sequences in the Combination table.
Top
Methods
  NameDescription
Public methodCompareTo(Object)
Compare two Combinations.
Public methodCompareTo(Combination)
Compare two Combinations.
Public methodCopyTo
Copy the entire sequence to the supplied destination.
Public methodEquals(Object)
Indicate whether two Combinations have the same value.
(Overrides ObjectEquals(Object).)
Public methodEquals(Combination)
Indicate whether two Combinations have the same value.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodCode exampleGetEnumerator
Enumerate all elements of a Combination.
Public methodGetHashCode
Get the hash oode of the Combination.
(Overrides ObjectGetHashCode.)
Public methodCode exampleGetRows
Iterate thru all rows of the Combination table for every Rank ascending.
Public methodCode exampleGetRowsForAllPicks
Iterate thru all rows of all Combination tables for every pick in the range (1..Picks).
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodStatic memberCode examplePermuteT
Apply a Combination sequence to rearrange the supplied list or array.
Public methodCode exampleToString
Provide a readable form of the Combination sequence.
(Overrides ObjectToString.)
Top
Operators
  NameDescription
Public operatorStatic memberEquality
Indicate whether 2 Combinations are equal.
Public operatorStatic memberGreaterThan
Indicate whether the left Combination is greater than the right Combination.
Public operatorStatic memberGreaterThanOrEqual
Indicate whether the left Combination is greater than or equal to the right Combination.
Public operatorStatic memberInequality
Indicate whether 2 Combinations are not equal.
Public operatorStatic memberLessThan
Indicate whether the left Combination is less than the right Combination.
Public operatorStatic memberLessThanOrEqual
Indicate whether the left Combination is less than or equal to the right Combination.
Top
Remarks

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

Examples

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 }

See Also