From e5f7e4721382852a01f12472a5336008d89a22e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Doblas=20Jim=C3=A9nez?= Date: Tue, 28 Sep 2021 10:14:40 +0200 Subject: [PATCH] Use benchmark macro --- src/Julia/Problems001-050/Problem002.jl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Julia/Problems001-050/Problem002.jl b/src/Julia/Problems001-050/Problem002.jl index d085eb1..432a1dc 100644 --- a/src/Julia/Problems001-050/Problem002.jl +++ b/src/Julia/Problems001-050/Problem002.jl @@ -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 @@ -37,4 +40,4 @@ end println("Time to evaluate Problem 2:") @btime Problem2() println("") -println("Result for Problem 2: ", Problem2()) \ No newline at end of file +println("Result for Problem 2: ", Problem2())