Use benchmark macro
This commit is contained in:
parent
89caae5244
commit
e5f7e47213
@ -5,7 +5,8 @@ Created on 08 Jun 2021
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for Problem 2 of Project Euler
|
||||
https://projecteuler.net/problem=2 =#
|
||||
https://projecteuler.net/problem=2
|
||||
=#
|
||||
|
||||
using BenchmarkTools
|
||||
|
||||
@ -14,15 +15,17 @@ function Problem2()
|
||||
Each new term in the Fibonacci sequence is generated by adding the
|
||||
previous two terms. By starting with 1 and 2, the first 10 terms will be:
|
||||
|
||||
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
|
||||
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
|
||||
|
||||
Find the sum of all the even-valued terms in the sequence which do not
|
||||
exceed four million. =#
|
||||
exceed four million.
|
||||
=#
|
||||
|
||||
ans = 0
|
||||
limit = 4_000_000
|
||||
x, y = 1, 1
|
||||
z = x + y # Because every third Fibonacci number is even
|
||||
# Because every third Fibonacci number is even
|
||||
z = x + y
|
||||
while z <= limit
|
||||
ans += z
|
||||
x = y + z
|
||||
|
Loading…
x
Reference in New Issue
Block a user