Click or drag to resize

PermutationPermuteT Method

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

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

Parameters

arrangement
Type: Kaos.CombinatoricsPermutation
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
Rearranged objects.
Exceptions
ExceptionCondition
ArgumentNullExceptionWhen arrangement or source is null.
ArgumentOutOfRangeExceptionWhen length of source is less than Picks.
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 PnExample03
    {
        static void Main()
        {
            var things = new List<object>
            {
                new Fruit ("apple"),
                new Furniture ("bench"),
                new Furniture ("chair")
            };

            // Use permutations to get rearrangements of other objects:
            foreach (var row in new Permutation (things.Count).GetRows())
                Console.WriteLine (String.Join (" ", Permutation.Permute (row, things)));
        }

        /* Output:

        apple bench chair
        apple chair bench
        bench apple chair
        bench chair apple
        chair apple bench
        chair bench apple

        */
    }
}
See Also