Here is an example of Python code that generates sections:
cache = {} def p3(n,val=1): """Returns number of ascending partitions of n if all values are >= val""" if n==0: return 1 # No choice in partitioning key = n,val if key in cache: return cache[key] # Choose next value x r = sum(p3(nx,x) for x in xrange(val,n+1)) cache[key]=r return r def ascending_partition(n,k): """Generate the k lexicographically ordered partition of n into integer parts""" P = [] val = 1 # All values must be greater than this while n: # Choose the next number for x in xrange(val,n+1): count = p3(nx,x) if k >= count: # Keep trying to find the correct digit k -= count elif count: # Check that there are some valid positions with this digit # This must be the correct digit for this location P.append(x) n -= x val = x break return P n=5 for k in range(p3(n)): print k,ascending_partition(n,k)
He prints:
0 [1, 1, 1, 1, 1] 1 [1, 1, 1, 2] 2 [1, 1, 3] 3 [1, 2, 2] 4 [1, 4] 5 [2, 3] 6 [5]
This can be used to create an arbitrary partition without generating all intermediate ones. For example, there are 9253082936723602 sections 300.
print ascending_partition(300,10**15)
prints
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 5, 7, 8, 8, 11, 12, 13, 14, 14, 17, 17, 48, 52]