diff --git a/src/Julia/Problems001-050/Problem001.jl b/src/Julia/Problems001-050/Problem001.jl index e989b3e..3aaf070 100644 --- a/src/Julia/Problems001-050/Problem001.jl +++ b/src/Julia/Problems001-050/Problem001.jl @@ -18,7 +18,7 @@ function Problem1() Find the sum of all the multiples of 3 or 5 below 1000. =# - ans = sum(x for x in 0:999 if x%3==0 || x%5==0) + ans = sum(x for x in 0:999 if x % 3 == 0 || x % 5 == 0) return ans end diff --git a/src/Julia/Problems001-050/Problem004.jl b/src/Julia/Problems001-050/Problem004.jl index c61a06b..4feb1bf 100644 --- a/src/Julia/Problems001-050/Problem004.jl +++ b/src/Julia/Problems001-050/Problem004.jl @@ -8,18 +8,14 @@ Solution for Problem 4 of Project Euler https://projecteuler.net/problem=4 =# using BenchmarkTools -using Profile -function ispalindrome(n::Int64) - # return digits(n) == reverse!(digits(n)) - for i in zip(digits(n), reverse!(digits(n))) - if i[1] ≠ i[end] - return false - end - end - return true + +function ispalindrome(n) + s = string(n) + s == reverse(s) end + function Problem4() #= A palindromic number reads the same both ways. The largest palindrome made @@ -28,10 +24,9 @@ function Problem4() Find the largest palindrome made from the product of two 3-digit numbers. =# ans = 10_001 - for i in 100:999, j in i:999 - num = i * j - if (num > ans) && ispalindrome(num) - ans = num + for i = 100:999, j = i:999 + if ((i * j > ans) && ispalindrome(i * j)) + ans = i * j end end diff --git a/src/Julia/Problems001-050/Problem005.jl b/src/Julia/Problems001-050/Problem005.jl index 515e27a..18dc5cf 100644 --- a/src/Julia/Problems001-050/Problem005.jl +++ b/src/Julia/Problems001-050/Problem005.jl @@ -25,7 +25,7 @@ function Problem5() 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 + for i = 1:21 ans *= i ÷ gcd(i, ans) end