Click or drag to resize

CombinationPermuteT Method

Apply a Combination sequence to rearrange the supplied list or array.

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

Parameters

arrangement
Type: Kaos.CombinatoricsCombination
New arrangement for items.
source
Type: System.Collections.GenericIListT
List of items to rearrange.

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 length of source is less than arrangement.Choices.
Examples
C#
using System;
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 CnExample03
    {
        static void Main()
        {
            object[] things =
            {
                new Fruit ("apple"),
                new Furniture ("bench"),
                new Furniture ("chair"),
                new Fruit ("durian"),
                new Fruit ("eggplant")
            };

            // Use k-combinations to get rearrangements of other objects:
            foreach (var row in new Combination (things.Length, 3).GetRows())
                Console.WriteLine (String.Join (" ", Combination.Permute (row, things)));
        }

        /* Output:

        apple bench chair
        apple bench durian
        apple bench eggplant
        apple chair durian
        apple chair eggplant
        apple durian eggplant
        bench chair durian
        bench chair eggplant
        bench durian eggplant
        chair durian eggplant

        */
    }
}
See Also