[Greenbuilding] Pithy python
nick pine
nick at early.com
Sat Jan 22 06:46:05 CST 2011
Nathan Hurst writes:
>nick pine wrote:
>> 2011 is the sum of 11 consecutive primes.
python
>>> primes = [2]
>>> for i in range(2, 2011):
... if all((i % x) for x in primes):
... primes.append(i)
...
>>> firstprime = bisect.bisect_left([sum(primes[i:i+11]) for i in
range(len(primes))], 2011)
>>> print firstprime
36
>>> sum( primes[36:36+11])
2011
>>> primes[36:36+11]
[157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211]
njh
More information about the Greenbuilding
mailing list