CSharp · Console
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
static IEnumerable<IEnumerable<T>> GetPermutations<T>(IEnumerable<T> list, int length)
{
if (length == 1) return list.Select(t => new T[] { t });
return GetPermutations(list, length - 1)
.SelectMany(t => list.Where(e => !t.Contains(e)),
(t1, t2) => t1.Concat(new T[] { t2 }));
}
public static void Main()
{
char[] aakkoset = new[] {'a', 'b', 'c'};
foreach (var permutaatio in GetPermutations(aakkoset, 3))
{
Console.WriteLine(string.Join(',', permutaatio));
}
}
}