Solution to problem 40 in Julia
This commit is contained in:
parent
0b579ba6dc
commit
7adb7a02ca
40
src/Julia/Problem040.jl
Normal file
40
src/Julia/Problem040.jl
Normal file
@ -0,0 +1,40 @@
|
||||
#=
|
||||
Created on 10 Sep 2021
|
||||
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for Problem 40 of Project Euler
|
||||
https://projecteuler.net/problem=40
|
||||
=#
|
||||
|
||||
using BenchmarkTools
|
||||
|
||||
function Problem40()
|
||||
#=
|
||||
An irrational decimal fraction is created by concatenating the positive integers:
|
||||
|
||||
0.123456789101112131415161718192021...
|
||||
|
||||
It can be seen that the 12th digit of the fractional part is 1.
|
||||
|
||||
If d_n represents the n^th digit of the fractional part, find the value of the following expression.
|
||||
|
||||
d_1 × d_{10} × d_{100} × d_{1_000} × d_{10_000} × d_{100_000} × d_{1_000_000}
|
||||
|
||||
=#
|
||||
ans = 1
|
||||
fraction = join([i for i in 1:1_000_000])
|
||||
|
||||
for i in 0:6
|
||||
ans *= parse(Int, fraction[10^i])
|
||||
end
|
||||
|
||||
return ans
|
||||
end
|
||||
|
||||
|
||||
println("Time to evaluate Problem 40:")
|
||||
@btime Problem40()
|
||||
println("")
|
||||
println("Result for Problem 40: ", Problem40())
|
Loading…
x
Reference in New Issue
Block a user