From 0b579ba6dc99299c0e2845347684c22f015af5fc Mon Sep 17 00:00:00 2001 From: daviddoji Date: Fri, 10 Sep 2021 11:00:14 +0200 Subject: [PATCH] Solution to problem 40 --- src/Python/Problem040.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/Python/Problem040.py diff --git a/src/Python/Problem040.py b/src/Python/Problem040.py new file mode 100644 index 0000000..47831e7 --- /dev/null +++ b/src/Python/Problem040.py @@ -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()}") \ No newline at end of file