Solved another Project Euler problem today. From the site:
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 dn represents the nth digit of the fractional part, find the value of the following expression.
d1 d10 d100 d1000 d10000 d100000 d1000000
My original intentions were to figure out an elegant formula for deriving dn given some n. I thought about it for a few minutes and figured it’d be interesting to see if the straight brute force solution was quick enough. So I quickly coded it up in python, and sure enough, it’s sub-second and therefore easily quick enough.
[email protected]:~/proj_euler$ time python prob40.py
for n in range(1,1000001):
list += str(n)
answers = [list, list, list, list, list, list, list]
prod = 1
for n in answers:
prod = prod * int(n)