Recent Comments On Blog

rss

This is fun!

n! means n x (n - 1) x ... x 3 x 2 x 1

Find the sum of the digits in the number 100!

reduce (lambda x,y: int (x) + int (y),
            str (reduce (lambda x,y: x * y,
                               xrange (100, 0, -1))))
 

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

def fibonacci(limit):
        a, b = 0, 1
        while a < limit:
                yield a
                a, b = b, a + b

print sum (filter (lambda x: x % 2 == 0, fibonacci (4e6)))
 
Trackback URI: http://www.ceyusa.com/blog/index.php/trackback/518

Leave a Comment

Write the captcha code you are seeing.

Comment XML feeds: RSS | Atom