Esempio n. 1
0
def p2(lt=4000000, fltr=lambda x: x % 2 == 0):
    """P2: By considering the terms in the Fibonacci sequence whose
    values do not exceed four million, find the sum of the even-valued
    terms.
    """
    fg = nttools.gen_fib()
    # filter and sum even elements of fibonacci series up to value 'lt'
    return reduce(op.add, filter(fltr, takewhile(lambda x: x < lt, fg)))
Esempio n. 2
0
def p25():
    for i, n in enumerate(nttools.gen_fib()):
        if len(str(n)) >= 1000:
            return (i, n)