Peter Pearson ha scritto:
On Wed, 19 May 2010 21:58:04 +0200, superpollo <ute...@esempio.net> wrote:
... how many positive integers less than n have digits that sum up to m:
If it's important for the function to execute quickly for large n,
you might get a useful speedup by testing only every ninth integer,
since any two integers whose digits add up to m differ by a multiple
of 9. A simple application of this observation would be to test
range( m % 9, n, 9 ) rather than testing range( 1, n ).
I suspect that further applications of number theory would
provide additional, substantial speedups, but this wanders
away from the subject of Python.
great suggestion, thanks!
--
http://mail.python.org/mailman/listinfo/python-list