I have a list of numbers like 1,2,3 and I want to find all the combination patterns that sum up to a particular number like 5. For example:
Sum=5 Numbers:1,2
public static List> Partition(int n, int max, string prefix) { if (n == 0) { _results.Add(prefix.Split(new char[] { ',' }).ToList()); } for (int i = Math.Min(max, n); i >= 1; i--) { Partition(n - i, i, prefix + "," + i); } return _results; }