Naming - Use `camelCase` for local variable names. And, use a meaningful name if *possible*. //var List1 = new List<int>{1,2,3,4,5,6,7,8,9}; var validNumbers = new List<int>{1,2,3,4,5,6,7,8,9}; Use pluralized noun for variable of collection type. //var combo = ... /*combo contains all possible combinations, not just one*/ var combos Code - - You don't need to enumerate the numbers 1 to 9. A `Enumerable.Range` will do the job. - The chain of `!exceptions.Contains(x)` is rather inefficient and redundant. You can avoid them by removing the exceptions from the start with `IEnumerable.Except`. - You can reuse the same list in your LINQ. - You can reuse the same name for your lambdas given they are not within the same parentheses. (Not really a big problem) <!----> Result : var validNumbers = Enumerable.Range(1, 9).Except(exceptions); var combos = (from a in validNumbers from b in validNumbers from b in validNumbers // Cartesian product where a > b && b > c && // exclude duplicates a + b + c == target // add up to the target select new List<int>{ a, b , c}) .OrderByDescending(x => x[0]) .ThenByDescending(x => x[1]) .ThenByDescending(x => x[2]); --- In the last 2 blocks of the code, `Console.Write` was repeatedly called within the `for loop`. You can join them together with `String.Join` before printing it to the console. Results : foreach(var item in combos) Console.WriteLine(string.Join("", item)); Console.Write("excluding " + string.Join(" ", exceptions));