private void TrySubPermutations(List <int>[] list, int[,] matrix, int counter) { var perms = PermutationsGenerator.Permutations(list [counter]); foreach (int[] perm in perms) { int[,] clone = (int[, ])matrix.Clone(); for (int i = 0; i < Size; i++) { clone[counter, i] = perm[i]; } if (counter == Size - 1) { if (ValidMagicSquare(clone)) { clone.PrintMatrix(); Counter++; Console.WriteLine("{0} squares found so far.", Counter); Console.WriteLine(); } continue; } if (IsValidOption(clone)) { TrySubPermutations(list, clone, counter + 1); } } }
private void TryPermutations(List <List <int> > current) { List <List <int>[]> listsPerm = PermutationsGenerator.Permutations(current); foreach (List <int>[] list in listsPerm) { TrySubPermutations(list, new int[Size, Size], 0); } }