On 19/06/2010 11:36, Stefan Behnel wrote:
Mark Lawrence, 18.06.2010 17:53:
... *AND* (looking at your email address) Germany loosing in the world
cup. :(
Yep, we always do that once at the early stages of a world cup. Pretty
good camouflage, still works most of the time.
Stefan
Yes, but tr
Mark Lawrence, 18.06.2010 17:53:
... *AND* (looking at your email address) Germany loosing in the world
cup. :(
Yep, we always do that once at the early stages of a world cup. Pretty good
camouflage, still works most of the time.
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
On 06/18/2010 05:53 PM, Mark Lawrence wrote:
> Andre, looks like a really bad day for you then, *TWO* nights out with
> me *AND* (looking at your email address) Germany loosing in the world
> cup. :(
There are days one looses and there are days the ot
On 18/06/2010 16:26, Andre Alexander Bell wrote:
On 06/18/2010 03:32 PM, Mark Lawrence wrote:
The good news is that this is easily the fastest piece of code that I've
seen yet. The bad news is that first prize in the speed competition is
a night out with me. :)
Well, that actually means that
On 06/18/2010 03:32 PM, Mark Lawrence wrote:
> The good news is that this is easily the fastest piece of code that I've
> seen yet. The bad news is that first prize in the speed competition is
> a night out with me. :)
Well, that actually means that Stefan Behnel will run my solution
through cyth
On 18/06/2010 16:00, Steven D'Aprano wrote:
On Fri, 18 Jun 2010 14:32:30 +0100, Mark Lawrence wrote:
The good news is that this is easily the fastest piece of code that I've
seen yet. The bad news is that first prize in the speed competition is
a night out with me.
I suppose second prize is
On Fri, 18 Jun 2010 14:32:30 +0100, Mark Lawrence wrote:
> The good news is that this is easily the fastest piece of code that I've
> seen yet. The bad news is that first prize in the speed competition is
> a night out with me.
I suppose second prize is two nights out with you?
--
Steven
--
On 18/06/2010 10:23, Andre Alexander Bell wrote:
On 06/16/2010 12:47 PM, Lie Ryan wrote:
Probably bending the rules a little bit:
sum(x**2 - 8*x - 20 for x in range(1, 2010, 5))
536926141
Bending them even further, the sum of the squares from 1 to N is given by
(1) N*(N+1)*(2*N+1)/6.
The
Peter Otten, 18.06.2010 12:14:
Stefan Behnel wrote:
Andre Alexander Bell, 18.06.2010 11:23:
On 06/16/2010 12:47 PM, Lie Ryan wrote:
Probably bending the rules a little bit:
sum(x**2 - 8*x - 20 for x in range(1, 2010, 5))
536926141
Bending them even further, the sum of the squares from 1
Stefan Behnel wrote:
> Andre Alexander Bell, 18.06.2010 11:23:
>> On 06/16/2010 12:47 PM, Lie Ryan wrote:
>>> Probably bending the rules a little bit:
>>>
>> sum(x**2 - 8*x - 20 for x in range(1, 2010, 5))
>>> 536926141
>>
>> Bending them even further, the sum of the squares from 1 to N is giv
Andre Alexander Bell, 18.06.2010 11:23:
On 06/16/2010 12:47 PM, Lie Ryan wrote:
Probably bending the rules a little bit:
sum(x**2 - 8*x - 20 for x in range(1, 2010, 5))
536926141
Bending them even further, the sum of the squares from 1 to N is given by
(1) N*(N+1)*(2*N+1)/6.
The given pro
On 06/16/2010 12:47 PM, Lie Ryan wrote:
> Probably bending the rules a little bit:
>
sum(x**2 - 8*x - 20 for x in range(1, 2010, 5))
> 536926141
Bending them even further, the sum of the squares from 1 to N is given by
(1) N*(N+1)*(2*N+1)/6.
The given problem can be divided into five sums
Ignacio Mondino wrote:
On Tue, Jun 15, 2010 at 8:49 AM, superpollo wrote:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
my solution:
s = 0
for i in range(1, 2011):
...
"Lie Ryan" wrote in message
news:4c18a...@dnews.tpgi.com.au...
> Probably bending the rules a little bit:
>
sum(x**2 - 8*x - 20 for x in range(1, 2010, 5))
> 536926141
Or, letting Python do the algera for you:
>>> from sympy import var, sum
>>> dummy = var('j k')
>>> k = (5 * j) + 1
>>>
Jussi Piitulainen, 16.06.2010 13:10:
Lie Ryan writes:
On 06/15/10 21:49, superpollo wrote:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each
three consecutive + must be followed by two - (^ meaning ** in
this context)
[...]
Probably bending the rule
Lie Ryan writes:
> On 06/15/10 21:49, superpollo wrote:
> > goal (from e.c.m.): evaluate
> > 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each
> > three consecutive + must be followed by two - (^ meaning ** in
> > this context)
[...]
> Probably bending the rules a little bit:
>
> >>
On 06/15/10 21:49, superpollo wrote:
> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)
>
> my solution:
>
s = 0
for i in range(1, 2011):
> s += i**2
> .
On Jun 15, 2:37 pm, Peter Otten <__pete...@web.de> wrote:
> >>> from itertools import cycle, izip
> >>> sum(sign*i*i for sign, i in izip(cycle([1]*3+[-1]*2), range(1, 2011)))
Wow!! :D
I didn't knew cycle, great! With that i can reduce my solution (which
isn't still elegant as your) to:
print redu
On Jun 15, 1:49 pm, superpollo wrote:
> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)
My functional approach :)
from operator import add
from functools import reduce
On Tue, Jun 15, 2010 at 9:26 AM, Ian Kelly wrote:
> On Tue, Jun 15, 2010 at 6:21 AM, Alain Ketterlin
> wrote:
> > You compute i**2 too many times (7/5 times more than necessary) and
> > twice too many modulos. I suggest:
> >
> > c = { 0:1, 1:1, 2:1, 3:-1, 4:-1 }
> > #or, why not: c = lambda i :
On Tue, Jun 15, 2010 at 8:49 AM, superpollo wrote:
> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)
>
> my solution:
>
s = 0
for i in range(1, 2011):
> ... s
Paul Rubin ha scritto:
superpollo writes:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
print sum([-1,1,1,1,-1][i%5]*i**2 for i in xrange(1,2011))
beautiful.
thx
--
h
superpollo writes:
> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)
print sum([-1,1,1,1,-1][i%5]*i**2 for i in xrange(1,2011))
--
http://mail.python.org/mailman/listinfo
On Tue, Jun 15, 2010 at 6:21 AM, Alain Ketterlin
wrote:
> You compute i**2 too many times (7/5 times more than necessary) and
> twice too many modulos. I suggest:
>
> c = { 0:1, 1:1, 2:1, 3:-1, 4:-1 }
> #or, why not: c = lambda i : +1 if (i%5) < 3 else -1
>
> s = 0
> for i in range(1,2011):
> s
Stefan Behnel wrote:
> superpollo, 15.06.2010 14:55:
>> Peter Otten ha scritto:
>>> superpollo wrote:
>>>
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
>>>
>>>
Stefan Behnel ha scritto:
superpollo, 15.06.2010 14:55:
Peter Otten ha scritto:
superpollo wrote:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
from itertools import
superpollo, 15.06.2010 14:55:
Peter Otten ha scritto:
superpollo wrote:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
from itertools import cycle, izip
sum(sign*i*i fo
>>> sum(i*i*(-1)**((i % 5) / 4 + (i + 4) % 5 / 4) for i in range(1,2011))
536926141
On Tue, Jun 15, 2010 at 6:25 PM, superpollo wrote:
> superpollo ha scritto:
>
> Peter Otten ha scritto:
>>
>>> superpollo wrote:
>>>
>>> goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-1
superpollo wrote:
superpollo ha scritto:
Peter Otten ha scritto:
superpollo wrote:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
from itertools import cycle, izip
sum
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
On 15 June 2010 22:55, superpollo wrote:
> Peter Otten ha scritto:
>
> superpollo wrote:
>>
>> goal (from e.c.m.): evaluate
>>> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
>>> consecutive + must be followed by two - (^ meaning ** in this context)
>>>
>>
>> from iterto
Stefan Behnel, 15.06.2010 14:23:
superpollo, 15.06.2010 13:49:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
my solution:
>>> s = 0
>>> for i in range(1, 2011):
... s +=
superpollo ha scritto:
Peter Otten ha scritto:
superpollo wrote:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
from itertools import cycle, izip
sum(sign*i*i for sign,
Peter Otten ha scritto:
superpollo wrote:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
from itertools import cycle, izip
sum(sign*i*i for sign, i in izip(cycle([1]*3+[
superpollo wrote:
> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)
>>> from itertools import cycle, izip
>>> sum(sign*i*i for sign, i in izip(cycle([1]*3+[-1]*2), range(1
superpollo writes:
> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)
>
> my solution:
>
> >>> s = 0
> >>> for i in range(1, 2011):
> ... s += i**2
> ... if not
Ulrich Eckhardt ha scritto:
superpollo wrote:
... s += i**2
... if not (i+1)%5:
... s -= 2*i**2
... if not i%5:
... s -= 2*i**2
if not (i % 5) in [1, 2]:
s += i**2
else:
s -= i**2
Untested code.
does not work:
>>> s = 0
>>> for i in range(1, 2011):
...
superpollo writes:
> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)
>
> my solution:
>
s = 0
for i in range(1, 2011):
> ... s += i**2
> ... if not (i+1)
superpollo, 15.06.2010 13:49:
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
my solution:
>>> s = 0
>>> for i in range(1, 2011):
... s += i**2
... if not (i+1)%5:
... s -
superpollo wrote:
> ... s += i**2
> ... if not (i+1)%5:
> ... s -= 2*i**2
> ... if not i%5:
> ... s -= 2*i**2
if not (i % 5) in [1, 2]:
s += i**2
else:
s -= i**2
Untested code.
Uli
--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR
On 15 June 2010 21:49, superpollo wrote:
> goal (from e.c.m.): evaluate
> 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
> consecutive + must be followed by two - (^ meaning ** in this context)
>
Obligatory one-liner:
>>> sum((1, 1, 1, -1, -1)[(x-1) % 5] * x**2 for x in x
goal (from e.c.m.): evaluate
1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three
consecutive + must be followed by two - (^ meaning ** in this context)
my solution:
>>> s = 0
>>> for i in range(1, 2011):
... s += i**2
... if not (i+1)%5:
... s -= 2*i**2
...
ShashiGowda wrote:
I am writing a package manager and stuck unable to write the version
sorting function the algorithm is here
http://www.linux.gr/cgi-bin/man/man2html?deb-version+5
and all other info is also in it please tell me how to do lexical
comparision in python it'll be cool if you just
On Oct 9, 7:29 am, ShashiGowda <[EMAIL PROTECTED]> wrote:
> I am writing a package manager and stuck unable to write the version
> sorting function the algorithm is
> herehttp://www.linux.gr/cgi-bin/man/man2html?deb-version+5
> and all other info is also in it please tell me how to do lexical
> co
I am writing a package manager and stuck unable to write the version
sorting function the algorithm is here
http://www.linux.gr/cgi-bin/man/man2html?deb-version+5
and all other info is also in it please tell me how to do lexical
comparision in python it'll be cool if you just write the code!
--
ht
45 matches
Mail list logo