Prob­lem

An irra­tional dec­i­mal frac­tion is cre­ated by con­cate­nat­ing the pos­i­tive integers:

0.123456789101112131415161718192021…

It can be seen that the 12th digit of the frac­tional part is 1.

If dn rep­re­sents the nth digit of the frac­tional part, find the value of the fol­low­ing expression.

d1 x d10 x d100 x d1000 x d10000 x d100000 x d1000000

Solu­tion

A pretty straight forward solution, the only trick is to turn the sequence of natural numbers 1, 2, 3, … 11, 12, 13.. into a continuous sequence of individual numbers. I did so by taking each number and turning it into a string array of its digits (e.g. 11 –> {"1"; "1"}) and concatenating these arrays using Seq.collect.
Share

One Response to “Project Euler — Problem 40 Solution”

  1. […] you want to see pro­gram­ming solu­tions for the prob­lem I have found 2 dif­fer­ent approa­hes.  The Burn­ing Monk has a solu­tion for the prob­lem using linq. Free Lancers Unite has a C# solu­tion closer to what I […]

Leave a Reply