diff --git a/src/Julia/Problem005.jl b/src/Julia/Problem005.jl new file mode 100644 index 0000000..b61d5fb --- /dev/null +++ b/src/Julia/Problem005.jl @@ -0,0 +1,41 @@ +#= +Created on 20 Jun 2021 + +@author: David Doblas Jiménez +@email: daviddoji@pm.me + +Solution for Problem 5 of Project Euler +https://projecteuler.net/problem=5 +=# + +#= +The LCM of two natural numbers x and y is given by: +def lcm(x, y): + return x * y // math.gcd(x, y) + +It is possible to compute the LCM of more than two numbers by iteratively +computing the LCM of two numbers, i.e. LCM(a, b, c) = LCM(a, LCM(b, c)) +=# + + +function Problem5() + #= + 2520 is the smallest number that can be divided by each of the numbers + from 1 to 10 without any remainder. + + What is the smallest positive number that is evenly divisible by all of + the numbers from 1 to 20? + =# + ans = 1 + for i in 1:21 + ans *= i ÷ gcd(i, ans) + end + + return ans +end + + +println("Time to evaluate Problem 5:") +@time Problem5() +println("") +println("Result for Problem 5: ", Problem5())