Comboset Test - Combinations & Permutations

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.

 

Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

This program tests the generating option of our TComboset class  which generates combinations and permutations of various types.

Permutations are subsets selected from a set of objects in every possible order. That is, {1,2,3}, {1,3,2}, (2,1,3}, {2,3,1}, {3,1,2}, and {3,2,1} are all permutations of the set [1,2,3]. This listing the subsets is increasing alphabetical, also called Lexicographical Up. They could also logically be listed in reverse sequence, Lexicographical down.  If we imagine drawing 3 numbered slips of paper from a hat without replacing the slip between draws, permutations represent all possible outcomes. If, on the other hand, we replace each slip after drawing and stop after 3 draws, we would have many more possible outcomes (3x3x3) or 27 outcomes compared to 3x2x1=6 outcomes previously.  This With repeats option is available. 

Combinations on the other hand are selected so that no two subsets have the same members. There is only one way to select a combination of 3 out of 3 objects. For selecting two of three objects, the combinatorial subsets are {1,2}, {1,3}, and {2,3}. These also can be selected with or without repetition, and listed "Lexicographical Up" or "Lexicographical Down

For combinations, is also possible redefine the order of the members within each set. Normally they are arranged alphabetically, but if they can also be treated as if each subset were arranged in reverse order.  Is is called a CoLexicographic sequence (and just to make things a little more complicated the these subsets can be retrieved in Lexicographic sequence, Up or Down.

So there are 10 retrieval sequences:

bullet Permutations Lex up
bulletPermutations Lex down
bulletPermutations Repeat Lex up
bulletPermutations Repeat Lex down
bulletCombinations Lex up
bulletCombinations Lex down
bulletCombinations Repeat Lex up
bulletCombinations Repeat Lex down
bulletCombinations CoLex up
bulletCombinations CoLex down   

In addition functions are now included to return a Random member from any of the above types, to pass a rank (position in the list) and return that subset, and to Unrank - pass a subset and retrieve its Rank.

The best way to learn to use units to examine the source for the attached test program.  It tests all of the above options and also allows you to replace numeral with strings if you want to see arrangements of letters or car models or fruit.   

TComboset is contained in unit UComboV2 which is in turn zipped with other common usage modules in a Library source file which may be downloaded below.  The unit initializes a single instance of TComboset with name Combos.

November 24, 2013: ComboTest Version 2.0 posted today has a minor but significant change to allow larger, 64-bit, sample sizes to be analyzed.  The change was motivated by request from a college professor simulating a draw of 5 items from a set of 500 values with replacement.  There are more that 285 billion ways to do this.   The built in Random function in Delphi tops out at 32 bit, around 4 billion so I implemented a 64 bit Random Number Generator (RNG) to allow generating random samples  from the 285 billion possibilities. 

For programmers, the implications of this change ripples through three library units (UComboV2, MathsLib, and UBigIntsV4).  These changes will are now included in DFFLibV14.zip  and will require reloading that file to recompile.        

bulletDownload Combo Test Source (requires DFF Library Source DFFLibV02 or later)
bulletDownload Combo Test Executable
bulletDownload DFF Library Source  (Current version DFFLibV14_12Nov2016 )

 

bulletDownload Lazarus Source
bulletDownload current DFF Lazarus Library Source(DFFLazLib01)

 

 

 

Created:  April 3, 2005

Modified: February 18, 2016

 

 

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2016, Gary Darby    All rights reserved.