Julia で Project Euler #2「偶数のフィボナッチ数」


function f002(max::Int64)
    fibonacci_numbers = [1, 2]
    while true
        fib = sum(fibonacci_numbers[(end - 1):end])
        if fib > max
            break
        end
        push!(fibonacci_numbers, fib)
    end

    result = 0
    for fib in fibonacci_numbers
        if fib % 2 == 0
            result += fib
       end
    end

    return result
end

f002(90)
# 44

@time f002(400_0000)
# 4613732
# 0.000005 seconds