Solution to problem 40
This commit is contained in:
parent
a6cdae898a
commit
0b579ba6dc
43
src/Python/Problem040.py
Normal file
43
src/Python/Problem040.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Created on 23 Jun 2021
|
||||||
|
|
||||||
|
@author: David Doblas Jiménez
|
||||||
|
@email: daviddoji@pm.me
|
||||||
|
|
||||||
|
Solution for problem 40 of Project Euler
|
||||||
|
https://projecteuler.net/problem=40
|
||||||
|
"""
|
||||||
|
|
||||||
|
from utils import timeit
|
||||||
|
|
||||||
|
|
||||||
|
@timeit("Problem 40")
|
||||||
|
def compute():
|
||||||
|
"""
|
||||||
|
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}
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
fraction = ''
|
||||||
|
for i in range(1, 1_000_000):
|
||||||
|
fraction += str(i)
|
||||||
|
|
||||||
|
ans = 1
|
||||||
|
for i in range(7):
|
||||||
|
ans*= int(fraction[10**i - 1])
|
||||||
|
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
print(f"Result for Problem 40: {compute()}")
|
Loading…
x
Reference in New Issue
Block a user