title: c# Efficient algorithm to find a combination, which summation is equal to two known number, in two set of number
body: <p>Let's say there are three sets of numbers</p>
  
  <blockquote>
    <p>A
    1,2</p>
    
    <p>B
    3,4</p>
    
    <p>C
    5,6</p>
  </blockquote>
  
  <p>The result 
  <code>8,10</code>
  The number near the result</p>
  
  <p>I want to find out which one is can equal to a known set number. We can find out that B+C = result. Actually I found some algorithm method for a single number but what I need is multiple numbers. And I totally have no clue how to do it.</p>
  
  <p>I am wondering whether there is any efficient algorithm to find out such combination.</p>
  
  <p>I try with below code with single number. But totally no idea how to do double set number.</p>
  
  <pre><code>public static IEnumerable&lt;string&gt; GetCombinations(int[] set, int sum, string values) 
  {
      for (int i = 0; i &lt; set.Length; i++) 
      {
          int left = sum - set[i];
          string vals = set[i] + "," + values;
  
          if (left == 0) {
              yield return vals;
          } 
          else {
            int[] possible = set.Take(i).Where(n =&gt; n &lt;= sum).ToArray();
            if (possible.Length &gt; 0) {
                foreach (string s in GetCombinations(possible, left, vals)) {
                    yield return s;
                }
            }
          }
      }
  }
  </code></pre>
  
  <p>Thanks everyone. Forgive me for poor english.</p>