diff --git a/src/Julia/Problem049.jl b/src/Julia/Problem049.jl new file mode 100644 index 0000000..dc4ca17 --- /dev/null +++ b/src/Julia/Problem049.jl @@ -0,0 +1,44 @@ +#= +Created on 19 Sep 2021 + +@author: David Doblas Jiménez +@email: daviddoji@pm.me + +Solution for Problem 49 of Project Euler +https://projecteuler.net/problem=49 +=# + +using BenchmarkTools +using Primes + +function Problem49() + #= + The arithmetic sequence, 1487, 4817, 8147, in which each of the terms + increases by 3330, is unusual in two ways: + (i) each of the three terms are prime, and, + (ii) each of the 4-digit numbers are permutations of one another. + + There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, + exhibiting this property, but there is one other 4-digit increasing sequence. + + What 12-digit number do you form by concatenating the three terms in this sequence? + =# + ans = [] + primes_list = primes(1_000, 10_000) + + for number in primes_list + if sort(collect(digits(number))) == sort(collect(digits(number+3330))) == sort(collect(digits(number+6660))) + if number+3330 in primes_list && number+6660 in primes_list + push!(ans, (string(number)*string(number+3300)*string(number+6660))) + end + end + end + # return the second one + return ans[2] +end + + +println("Time to evaluate Problem 49:") +@btime Problem49() +println("") +println("Result for Problem 49: ", Problem49())