[Greenbuilding] Pithy python

John O'Brien john at boardom.ca
Sun Jan 23 09:37:29 CST 2011


Glad to see you've moved on from BASIC nick. ;)

python++

On Sat, Jan 22, 2011 at 7:46 AM, nick pine <nick at early.com> wrote:
> 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
>
> _______________________________________________
> Greenbuilding mailing list
> to Send a Message to the list, use the email address
> Greenbuilding at bioenergylists.org
>
> to UNSUBSCRIBE or Change your List Settings use the web page
> http://lists.bioenergylists.org/mailman/listinfo/greenbuilding_lists.bioenergylists.org
>




More information about the Greenbuilding mailing list