Solution to problem 33 in Julia

This commit is contained in:
David Doblas Jiménez 2021-09-01 10:44:39 +02:00
parent 548e212210
commit efe87996e5

51
src/Julia/Problem033.jl Normal file
View File

@ -0,0 +1,51 @@
#=
Created on 01 Sep 2021
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for Problem 33 of Project Euler
https://projecteuler.net/problem=33
=#
using BenchmarkTools
function Problem33()
#=
The fraction 49/98 is a curious fraction, as an inexperienced mathematician
in attempting to simplify it may incorrectly believe that 49/98 = 4/8,
which is correct, is obtained by cancelling the 9s.
We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
There are exactly four non-trivial examples of this type of fraction, less
than one in value, and containing two digits in the numerator and denominator.
If the product of these four fractions is given in its lowest common terms,
find the value of the denominator.
=#
numerator = 1
denominator = 1
for x in 10:99
for y in 10:99
if x < y
if reverse(digits(x))[2] == reverse(digits(y))[1]
if reverse(digits(y))[2] != 0
if reverse(digits(x))[1] / reverse(digits(y))[2] == x / y
numerator *= x
denominator *= y
end
end
end
end
end
end
return Int(denominator/numerator)
end
println("Time to evaluate Problem 33:")
@btime Problem33()
println("")
println("Result for Problem 33: ", Problem33())