This commit is contained in:
David Doblas Jiménez 2022-10-03 19:36:05 +02:00
parent d5b21cacef
commit 972c716993
3 changed files with 10 additions and 15 deletions

View File

@ -18,7 +18,7 @@ function Problem1()
Find the sum of all the multiples of 3 or 5 below 1000. 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 return ans
end end

View File

@ -8,18 +8,14 @@ Solution for Problem 4 of Project Euler
https://projecteuler.net/problem=4 =# https://projecteuler.net/problem=4 =#
using BenchmarkTools using BenchmarkTools
using Profile
function ispalindrome(n::Int64)
# return digits(n) == reverse!(digits(n)) function ispalindrome(n)
for i in zip(digits(n), reverse!(digits(n))) s = string(n)
if i[1] i[end] s == reverse(s)
return false
end
end
return true
end end
function Problem4() function Problem4()
#= #=
A palindromic number reads the same both ways. The largest palindrome made 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. =# Find the largest palindrome made from the product of two 3-digit numbers. =#
ans = 10_001 ans = 10_001
for i in 100:999, j in i:999 for i = 100:999, j = i:999
num = i * j if ((i * j > ans) && ispalindrome(i * j))
if (num > ans) && ispalindrome(num) ans = i * j
ans = num
end end
end end

View File

@ -25,7 +25,7 @@ function Problem5()
What is the smallest positive number that is evenly divisible by all of What is the smallest positive number that is evenly divisible by all of
the numbers from 1 to 20? =# the numbers from 1 to 20? =#
ans = 1 ans = 1
for i in 1:21 for i = 1:21
ans *= i ÷ gcd(i, ans) ans *= i ÷ gcd(i, ans)
end end