示例#1
0
文件: main.py 项目: mattjhussey/pemjh
def main():
    """ challenge138 """
    b1 = fibo()
    b2 = fibo()
    # Step b1 on
    for _ in range(2):
        next(b1)
    # Step b2 on
    for _ in range(5):
        next(b2)

    total = 0
    for _ in range(12):
        next_b = next(b1) * next(b2)

        v = ((next_b // 2)**2 + (next_b + 1)**2)**0.5
        if v == int(v):
            total += int(v)
        else:
            v = ((next_b // 2)**2 + (next_b - 1)**2)**0.5

            total += int(v)

        # Step on
        for _ in range(2):
            next(b1)
            next(b2)

    return total
示例#2
0
def golden_nuggets(num_to_gen):
    """ Generate a number of Golden Nuggets.
    A Golden Nugget is described here: https://projecteuler.net/problem=140 """

    nuggets = []
    remaining = num_to_gen

    # Need 2 for each, except the first
    fibs_needed = 2 * num_to_gen - 1
    fibs = list(islice(fibo(), 1, fibs_needed + 1))
    double_up = True
    fib_index = 0

    # Begin at 0 because the first step should inc twice to become 2
    current = 0
    while remaining > 0:
        fib = fibs[fib_index]

        # Skip 2 fibs next time
        fib_index += 2
        current += fib
        if double_up:
            current += fib
        double_up = not double_up
        nuggets.append(current)

        remaining -= 1

    return nuggets
示例#3
0
def test_fibo(take, expected):
    actual = list(takewhile(lambda x: x < take, fibo()))
    expect(actual).to.eq(expected)
示例#4
0
文件: main.py 项目: mattjhussey/pemjh
def main():
    """ challenge025 """
    return next(
        dropwhile(lambda x: len(str(x[1])) < 1000, enumerate(fibo(),
                                                             start=1)))[0]
示例#5
0
文件: main.py 项目: mattjhussey/pemjh
def main(limit):
    """ challenge2 """
    number_range = takewhile(lambda i: i < limit, fibo())
    even_numbers = (i for i in number_range if i % 2 == 0)
    return sum(even_numbers)