Как сделать все возможные комбинации? - C#
Формулировка задачи:
Есть Как перебрать все возможние 4 чисел (2,3,4,5),(2,4,5,6),(2,3,5,6)...
int[]mas=new int[5]{2,3,4,5,6}Решение задачи: «Как сделать все возможные комбинации?»
textual
Листинг программы
int[] mas = new int[]{2,3,4,5,6};
var combinations =
from a in mas
from b in mas
from c in mas
from d in mas
where
a != b && a != c && a != d
&& b != c && b != d
&& c != d
select Tuple.Create(a,b,c,d);
foreach (Tuple<int,int,int,int> t in combinations)
{
Console.WriteLine("{0}, {1}, {2}, {3}", t.Item1, t.Item2, t.Item3, t.Item4);
}