Question
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 represents the nth digit of the fractional part, find the value of the following expression.
Haskell
champernowne :: String
champernowne = foldr (\x acc -> (show x) ++ acc) "" [1..]
main :: IO ()
main = print $ product [read [champernowne !! (n - 1)] | n <- [10^x | x <- [0..6]]]
$ ghc -O2 -o champernowne champernowne.hs
$ time ./champernowne
real 0m0.060s
user 0m0.051s
sys 0m0.009s
Python
#!/usr/bin/env python
d = [int(digit) for digit in ''.join((str(digit) for digit in range(1, 10000001)))]
print(d[0] * d[9] * d[99] * d[999] * d[9999] * d[99999] * d[999999])