Beispiel #1
0
def problem_two(limit=4000000):
    """
    Find the sum of all the even-valued terms in the fibonacci sequence
    which do not exceed four million.
    """
    even_fibs = (fib(n) for n in count() if fib(n) % 2 == 0)
    return sum(takewhile(lambda x: x < limit, even_fibs))
Beispiel #2
0
def problem_25():
    """
    What is the first term in the Fibonacci sequence to contain 1000 digits?
    """
    digits = lambda x: len(str(x))
    for n in count(1):
        num = fib(n)
        if digits(num) < 1000: continue
        return n