[Tutor] Memory error - how to manage large data sets?
bob gailer
bgailer at gmail.com
Thu Jul 31 22:26:27 CEST 2008
Kepala Pening wrote:
> def sumEvenFibonacci( limit ):
> a, b = 1, 1 # don't waste with a = 0
> sum = 0
> while b < limit:
> if b%2 == 0: sum += b
> a, b = b, a + b
> return sum
>
> print sumEvenFibonacci( 2000000 )
>
>
>
Every 3rd element in the Fibonacci series is an even number. So one
could economize slightly:
def sumEvenFibonacci(limit):
a, b = 1, 1 # don't waste with a = 0
sum = 0
while b < limit:
a, b = b, a + b
sum += b
a, b = b, a + b
a, b = b, a + b
return sum
--
Bob Gailer
919-636-4239 Chapel Hill, NC
More information about the Tutor
mailing list