Arnaud and Terry, Great solutions both of you! Much nicer than mine. I particularly like Arnaud's latest one based on folding because it's so neat and conceptually simple. For me, it's the closest so far to my goal of the most elegant solution.
So anyone got an answer to which set of numbers gives the most targets from 100 onwards say (or from 0 onwards)? Is Python up to the task? A thought on that last one. Two ways to improve speed. First of all, you don't need to rerun from scratch for each target. Secondly, you can try multiple different sets of numbers at the same time by passing numpy arrays instead of single values (although you have to give up the commutativity and division by zero optimisations). Dan Goodman -- http://mail.python.org/mailman/listinfo/python-list