Solution to problem 36 in Julia

This commit is contained in:
David Doblas Jiménez 2021-09-04 17:16:37 +02:00
parent 9ffd20082d
commit 44ee008454

38
src/Julia/Problem036.jl Normal file
View File

@ -0,0 +1,38 @@
#=
Created on 04 Sep 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for Problem 36 of Project Euler
https://projecteuler.net/problem=36
=#
using BenchmarkTools
function is_palindrome(num)
return num == reverse(num)
end
function Problem36()
#=
The decimal number, 585 = 1001001001_2 (binary), is palindromic
in both bases.
Find the sum of all numbers, less than one million, which are palindromic
in base 10 and base 2.
=#
ans = 0
for n in 1:2:1_000_000
if is_palindrome(digits(n,base=10)) && is_palindrome(digits(n,base=2))
ans += n
end
end
return ans
end
println("Time to evaluate Problem 36:")
@btime Problem36()
println("")
println("Result for Problem 36: ", Problem36())