pythonize this!

Andre Alexander Bell python at andre-bell.de
Tue Jun 15 09:19:20 EDT 2010


On 06/15/2010 01:49 PM, superpollo wrote:
> my solution:
>
> [...]
> >>> print s
> 536926141

Or, if you would like to use numpy:

>>> import numpy
>>> squares = numpy.arange(1, 2011, dtype=numpy.int)**2
>>> signs = numpy.ones(len(squares), dtype=numpy.int)
>>> signs[3::5] = -1
>>> signs[4::5] = -1
>>> numpy.sum(signs*squares)
536926141

Cheers


Andre




More information about the Python-list mailing list