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
In [36]:
open System.Text
let limit = 1000000
let appendChampernowne (sb:StringBuilder) n =
sb.Append (string n) |> ignore
n
let rec buildChamp' (sb:StringBuilder) n =
if (sb.Length) > limit then (sb.ToString())
else buildChamp' sb (appendChampernowne sb (1 + n))
let buildChamp n =
buildChamp' (new StringBuilder()) n
let champernowne = (buildChamp 0).ToCharArray()
[1; 10; 100; 1000; 10000; 100000; 1000000;]
|> List.map (fun i -> champernowne.[i-1])
|> List.map (string >> int)
|> List.fold (fun acc element -> acc * element) 1
Out[36]:
In [ ]: