skip to main | skip to sidebar

Project Euler

Saturday, August 23, 2008

Euler Problem #2: Fibonacci Numbers

fibonacci() is from Diving Into Python by Mark Pilgrim

>>> def fibonacci():
... a,b = 0,1
... while a <= 4000000:
... yield a
... a,b = b, a + b
...
>>> total = 0
>>> for n in fibonacci():
... if n%2 == 0:
... total += n
...
>>> print total
4613732
Posted by JoBro Hater #3 at 3:41 PM

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ▼  2008 (36)
    • ►  October (9)
    • ►  September (17)
    • ▼  August (10)
      • Euler problem #10, sum of primes <2000000
      • Problem 9 Pythagorean triplet summing to 1000
      • Euler Problem 8: Find largest product of five cons...
      • Problem 7: FInd 10001st prime
      • Project Euler Problem #6
      • Problem #5: find smallest number evenly divisible ...
      • #4: Find largest palindrome produced by product of...
      • Project Euler #3: Find largest prime factor
      • Euler Problem #2: Fibonacci Numbers
      • First Problem: Find sum of all factors of 3 and 5 ...

About Me

JoBro Hater #3
View my complete profile