+#!/usr/bin/env python2.6

+This is a dynamic solution which runs efficiently. I did not think of this approach, but implemented it from the description at http://programmingpraxis.com/2010/11/09/subset-sums/.

+ """Solve sum of subsets for numbers.

+ numbers must be positive and in sorted order.

+ """number of subsets of numbers[:stop] which sum to target"""

+ if stop == 0: # empty set only matches if target is 0

+ if target == 0: # only empty set matches

+ result = f(stop - 1, target) # without last

+ last = numbers[stop - 1]

+ result += f(stop - 1, target - last) # with last

+ return sum(f(x, numbers[x]) for x in xrange(2, len(numbers)))

+ print "=", solve(numbers)

+show([3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99])

+# primes example from Praxis

+ """Return sieve for primes 2..stop."""

+ for x in xrange(2, stop):

+ for n in xrange(2 * x, stop, x):

+show(list(primes(2**10)))