Simple Examples

Coordinator
Sep 28, 2012 at 10:24 AM
Edited Sep 30, 2012 at 10:33 PM

The Permutations class is designed to be used with the IEnumerable<T> generic interface via extension methods, a simple example is:

using SimplePermutate;

....

  char[] chars = new char[] { "a", "b", "c" };

  var permutations = chars.Permutations(false, true);

 

OR

 

 

Imports .....SimplePermutate


....

        Dim chars As Char() = {"a"c, "b"c, "c"c}

        Dim result = chars.Permutations(False, True)

 

 

permutations will be an IEnumerable<IEnumerable<char>> ( IEnumerable(Of IEnumerable(Of Char)) ) which contains these elements:

aaa, aab, aac, aba, abb, abc, aca, acb, acc, baa, bab, bac, bba, bbb, bbc, bca, bcb, bcc, caa, cab, cac, cba, cbb, cbc, cca, ccb, ccc 

The first boolean parameter is whether or not order is ignored, if the order of the elements is ignored then only the first order of each combination of chars is returned, if it is not ignored then every possible sorting as well as every possible combination is returned. 

The second boolean parameter is whether elements can be repeated, if this parameter is true then each element in the input set can be repeated as many times as possible with in the output set. If it is false then  the items from the set specified can only be used once per output set.