Click or drag to resize

ProductPermuteT Method

Apply a Product sequence to select from the supplied lists or arrays.

Namespace:  Kaos.Combinatorics
Assembly:  KaosCombinatorics (in KaosCombinatorics.dll) Version: 5.0.0.6
Syntax
C#
public static List<T> Permute<T>(
	Product arrangement,
	IList<IList<T>> source
)

Parameters

arrangement
Type: Kaos.CombinatoricsProduct
New arrangement for items.
source
Type: System.Collections.GenericIListIListT
List of List of Items or arrays to rarrange.

Type Parameters

T
Type of items to rearrange.

Return Value

Type: ListT
List of rearranged items.
Exceptions
ExceptionCondition
ArgumentNullExceptionWhen arrangement or source is null.
ArgumentExceptionWhen not enough source sets.
IndexOutOfRangeException When supplied source list is too small.
Examples
C#
using System;
using System.Collections.Generic;
using Kaos.Combinatorics;

namespace ExampleApp
{
    public class Furniture
    {
        public string Name { get; private set; }
        public Furniture (string name) { Name = name; }
        public override string ToString() => Name;
    }

    public class Fruit
    {
        public string Name { get; private set; }
        public Fruit (string name) { Name = name; }
        public override string ToString() => Name;
    }

    class PtExample03
    {
        static void Main()
        {
            var colors = new List<object> { "aqua", "black", "crimson" };

            var things = new List<object>
            {
                new Fruit ("apple"),
                new Furniture ("bench"),
                new Furniture ("chair"),
                new Fruit ("durian"),
                new Fruit ("eggplant")
            };

            var lists = new List<object>[] { colors, things };
            int[] counts = { colors.Count, things.Count };

            // Use a cartesian product to get rearrangements of other objects:
            foreach (var row in new Product (counts).GetRows())
                Console.WriteLine (String.Join (" ", Product.Permute (row, lists)));
        }

        /* Output:

        aqua apple
        aqua bench
        aqua chair
        aqua durian
        aqua eggplant
        black apple
        black bench
        black chair
        black durian
        black eggplant
        crimson apple
        crimson bench
        crimson chair
        crimson durian
        crimson eggplant

        */
    }
}
See Also