private List<Combination> GeneratePermutations(Combination numbers) { List<Combination> permutations = new List<Combination>(); if (1 == numbers.Length) { permutations.Add (numbers); return permutations; } for (var i=0; i<numbers.Length; i++) { List<Combination> subPerm = GeneratePermutations (numbers.GetSubCombination(i, numbers.Step+1)); foreach (var sub in subPerm) { var newNumbers = new int[numbers.Length]; newNumbers [0] = numbers [i]; var length = sub.Length; Array.Copy (sub.Numbers, 0, newNumbers, 1, length); permutations.Add (new Combination(newNumbers, sub.Step)); } } return permutations; }