using System.Collections.Generic;
public static void Main()
int[] list = { 1, 2, 3, 4, 5, 6, 7, 8 };
var perms = GetAllPermutations(list, 8).ToArray();
perms = perms.Where(x => !SameGroup(x)).ToArray();
perms = perms.Where(x => !SameCountry(x)).ToArray();
string[] firsts = { "Chelsea", "Manc city", "Juventus", "Bayer", "Real", "Liverpool", "dortmunt", "Pari Saint" };
string[] seconds = { "Seville", "Porto", "Barcelona", "Atletiko", "Gladba", "Atalanta", "Lazzio", "Leipzig" };
int[,] probs = new int[8, 8];
foreach(var item in perms)
for(int i = 0; i < item.Length; i++)
for(int i = 0; i < 8; i++)
for(int j = 0; j < 8; j++)
Console.WriteLine("{0,-15} {1,-15} {2, -15}",firsts[i], seconds[j] , 1.0 * probs[i, j] / perms.Length);
static bool SameGroup(int[] list)
for(int i = 0; i < list.Length; i++)
static bool SameCountry(int[] list)
if(list[2] == 6) return true;
if(list[2] == 7) return true;
if(list[3] == 5) return true;
if(list[3] == 8) return true;
if(list[4] == 1) return true;
if(list[4] == 3) return true;
if(list[4] == 4) return true;
if(list[6] == 5) return true;
if(list[6] == 8) return true;
static IEnumerable<T[]> GetAllPermutations<T>(IEnumerable<T> list, int length)
return list.Select(t => new T[] { t });
return GetAllPermutations(list, length - 1)
.SelectMany(t => list.Where(e => !t.Contains(e)),
(t1, t2) => t1.Concat(new T[] { t2 }).ToArray()).ToArray();