Champernowne's constant

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 dn represents the nth digit of the fractional part, find the value of the following expression.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000


Idea

Naive solution.

Directly get the ith digit by calculation.


In [1]:
from functools import reduce
from operator import mul
from math import ceil
In [2]:
def get_digit(ith):
    start = 0
    for digit_number, total in enumerate(map(lambda i: pow(10, i) * 9, range(6)), 1):
        if ith > total * digit_number:
            start += total
            ith -= total * digit_number
        else:
            break
    k, r = ceil(ith / digit_number), (ith-1) % digit_number
    return int(str(start + k)[r])
In [3]:
get_digit(11)
Out[3]:
0
In [4]:
get_digit(12)
Out[4]:
1
In [5]:
get_digit(1)
Out[5]:
1
In [6]:
def solve():
    return reduce(mul, map(get_digit, map(lambda i: pow(10, i), range(7))), 1)
In [7]:
solve()
Out[7]:
210