If I have a sequence as follows (let\'s say it\'s an IEnumerable
):
[A, B, C, D, E]
Then what\'s the cleanest way to c
I've had success with IanG's PermuteUtils class:
char[] items = new char[] { 'A', 'B', 'C', 'D', 'E' };
foreach (IEnumerable permutation in PermuteUtils.Permute(items, 3)) {
Console.Write("[");
foreach (char c in permutation) {
Console.Write(" " + c);
}
Console.WriteLine(" ]");
}
Results in:
[ A B C ] [ A B D ] [ A B E ] [ A C B ] [ A C D ] [ A C E ] [ A D B ] [ A D C ] [ A D E ] [ A E B ] [ A E C ] [ A E D ] [ B A C ] [ B A D ] [ B A E ] [ B C A ] [ B C D ] [ B C E ] [ B D A ] [ B D C ] ...