title: Partitions of k parts with minimum and maximum part values
body: <p>How do I generate the partitions of a number that have exactly k parts, where each part has a minimum and maximum value?</p>
  
  <p>For example, If I want to select all partitions of 21 with 6 parts with minimum part value 3 and the maximum part value is 6, I should get the following partitions:</p>
  
  <pre><code>[3, 3, 3, 3, 3, 6]     
  [3, 3, 3, 3, 4, 5]
  [3, 3, 3, 4, 4, 4]
  </code></pre>
  
  <p>I have the following ascending partition code, courtesy of <a href="http://jeromekelleher.net/generating-integer-partitions.html" rel="nofollow noreferrer">http://jeromekelleher.net/generating-integer-partitions.html</a></p>
  
  <pre><code>def accel_asc(n):
      a = [0 for i in range(n + 1)]
      k = 1
      y = n - 1
      while k != 0:
          x = a[k - 1] + 1
          k -= 1
          while 2 * x &lt;= y:
              a[k] = x
              y -= x
              k += 1
          l = k + 1
          while x &lt;= y:
              a[k] = x
              a[l] = y
              yield a[:k + 2]
              x += 1
              y -= 1
          a[k] = x + y
          y = x + y - 1
          yield a[:k + 1]
  </code></pre>
  
  <p>and a simple fuction I wrote to only get the partitions I want from the function above:</p>
  
  <pre><code>def eligible_partitions(list_of_partitions, min_value, max_value, k):
       l = []
       for x in list_of_partitions:
            if min(x) &gt;= min_value and max(x) &lt;= max_value and len(x) == k:
                 l.append(x)
       return l
  </code></pre>
  
  <p>Instead of having to generate and loop through all of the partitions of a particular value, I only want to generate those that meet the specified criteria.</p>