[PyAR2] Programming Challenge II - One is the Magic Number

Jesse Jaggars jhjaggars at gmail.com
Tue Oct 28 06:09:45 CET 2008


sum(int(str(x).count("1")) for x in xrange(1000000))

Or, if you prefer to supply the parameters:

def howmany( needle, haystack ):
    return sum(int(str(z).count(str(needle))) for z in xrange(int(haystack)))


More information about the PyAR2 mailing list