project-euler/src/Julia/Problem036.jl

39 lines
777 B
Julia

#=
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())