title: Finding Combinations to the provided Sum value
body: <p>I have series of numbers like this</p>
  
  <pre><code>myvar = [57, 71, 87, 97, 99, 101, 103, 113, 114, 115, 128, 129, 131, 137, 147, 156, 163, 186]
  </code></pre>
  
  <p>Now I want to calculate all such possible combinations (of length 1 to 20) whose sum is equal to a given number <code>m</code>. </p>
  
  <p>I tried to solve with following code as :</p>
  
  <pre><code>def sum_count(m):    ## Where m is the sum required
  
      from itertools import combinations
  
      myseq = []
      for i in range(1,len(myvar)):
          mycomb = list(combinations(mass,i));  # Getting combinations of length i
          mycomb = [list(j) for j in mycomb];
          for j in range(len(mycomb)-1,-1,-1):
              if sum(mycomb[j]) == m:
                  myseq.append(mycomb[j])
  
      return(myseq)
  </code></pre>
  
  <p>When I put <code>m = 270</code> (for example) it gives me :</p>
  
  <pre><code>[[114, 156], [57, 99, 114]]
  </code></pre>
  
  <p>But is quite evident from the <code>myvar</code> that there are still other combinations which have a sum equal to 270. Where am I failing to comprehend.</p>