<reponame>omermikhailk/project-euler
from functools import lru_cache


@lru_cache(maxsize=None)
def fib(n):
    """
    Takes a term `n` and returns `fib(n)`.

    :param n: the term for the sequence
    :return: fib(n)
    """
    if n == 1:
        return 1
    elif n == 2:
        return 2
    else:
        return fib(n - 1) + fib(n - 2)


def sum_even_valued():
    n = 1
    while fib(n) <= 4_000_000:
        n += 1
    return sum([fib(i) for i in range(1, n) if not fib(i) % 2])


if __name__ == "__main__":
    print(sum_even_valued())

from functools import lru_cache


@lru_cache(maxsize=None)
def fib(n):
    """
    Takes a term `n` and returns `fib(n)`.

    :param n: the term for the sequence
    :return: fib(n)
    """
    if n == 1:
        return 1
    elif n == 2:
        return 2
    else:
        return fib(n - 1) + fib(n - 2)


def sum_even_valued():
    n = 1
    while fib(n) <= 4_000_000:
        n += 1
    return sum([fib(i) for i in range(1, n) if not fib(i) % 2])


if __name__ == "__main__":
    print(sum_even_valued())
Takes a term `n` and returns `fib(n)`.      :param n: the term for the sequence     :return: fib(n)