Solution for problem 2 in Julia
This commit is contained in:
parent
b7392266cf
commit
e45bcfdc4d
34
src/Julia/Problem002.jl
Normal file
34
src/Julia/Problem002.jl
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#=
|
||||||
|
Created on 08 Jun 2021
|
||||||
|
|
||||||
|
@author: David Doblas Jiménez
|
||||||
|
@email: daviddoji@pm.me
|
||||||
|
|
||||||
|
Solution for Problem 2 of Project Euler
|
||||||
|
https://projecteuler.net/problem=2
|
||||||
|
=#
|
||||||
|
|
||||||
|
function Problem2()
|
||||||
|
#=
|
||||||
|
Statement
|
||||||
|
=#
|
||||||
|
|
||||||
|
ans = 0
|
||||||
|
limit = 4_000_000
|
||||||
|
x, y = 1, 1
|
||||||
|
z = x + y # Because every third Fibonacci number is even
|
||||||
|
while z <= limit
|
||||||
|
ans += z
|
||||||
|
x = y + z
|
||||||
|
y = z + x
|
||||||
|
z = x + y
|
||||||
|
end
|
||||||
|
|
||||||
|
return ans
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
println("Time to evaluate Problem 2:")
|
||||||
|
@time Problem2()
|
||||||
|
println("")
|
||||||
|
println("Result for Problem 2: ", Problem2())
|
Loading…
x
Reference in New Issue
Block a user