Project Euler Problem 040


An irrational decimal fraction is created by concatenating the positive integers:


It can be seen that the 12th digit of the fractional part is 1.

If $d_n$ represents the nth digit of the fractional part, find the value of the following expression.

$d_1 * d_{10} * d_{100} * d_{1000} * d_{10000} * d_{100000} * d_{1000000}$


Straight-forward solution using Python:

from functools import reduce
if __name__ == '__main__':
    decimal_part = []
    i = 1
    while len(decimal_part) < 1000000:
        i += 1
    decimal_part = ''.join(decimal_part)
    result = reduce(lambda x, y: x * int(decimal_part[int('9' * y)]), range(1, 6), int(decimal_part[0]))
    print("The result is:", result)

The Python file is available for download here.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License