How to implement the following algorithm in Delphi (Object Pascal) in a way that:
- Each alpha numeric item will be a single object (in my case a reference to file strings).
- to be possible to enumerate (to output) each pick state/combination.
- imagine the columns of an abacus; all have the same size (according to its base). I need columns with different sizes. (in my case, sets of file strings with different sizes)
Last EDIT: Please, see Python intertools implementation.
Similar algorithms in other languages: c#, ruby, java, php
ALGORITHM
Consider the following sets and its members:
S1 = {a1, a2, a3, a4, a5}
S2 = {b1, b2, b3, b4}
S3 = {c1, c2, c3, c4, c5}
Pick the first member of each set (P = Pick States):
P1 = {a1, b1, c1}
Then, increment the first until its limit:
P2 = {a2, b1, c1} P3 = {a3, b1, c1} P4 = {a4, b1, c1} P5 = {a5, b1, c1}
Then, reset the first Set, and increment 'one' the second set;
P6 = {a1, b2, c1}
Increment the first set again... and so on... reseting the first and the second set for each 'plus one' on third set.
P7 = {a2, b2, c1}
Regarding the fundamental principle of counting or principle of multiplication, this algorithm would generate 100 pick states/combinations.
P100 = {a5, b4, c5}