mirror of
https://github.com/correl/euler.git
synced 2024-11-30 19:19:54 +00:00
Problem 040
git-svn-id: file:///srv/svn/euler@67 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
This commit is contained in:
parent
54dedd8f7f
commit
8ab85e4082
1 changed files with 38 additions and 0 deletions
38
e040.py
Normal file
38
e040.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
"""Finding the nth digit of the fractional part of the irrational number.
|
||||||
|
|
||||||
|
An irrational decimal fraction is created by concatenating the positive integers:
|
||||||
|
0.12345678910[1]112131415161718192021...
|
||||||
|
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
|
from e011 import product
|
||||||
|
|
||||||
|
def irrational_generator():
|
||||||
|
i = 0
|
||||||
|
pos = 0
|
||||||
|
data = []
|
||||||
|
while True:
|
||||||
|
i = i + 1
|
||||||
|
s = str(i)
|
||||||
|
for c in s:
|
||||||
|
yield int(c)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
values = []
|
||||||
|
counter = 0
|
||||||
|
stops = [10**n for n in range(7)]
|
||||||
|
for i in irrational_generator():
|
||||||
|
counter = counter + 1
|
||||||
|
if counter in stops:
|
||||||
|
values.append(i)
|
||||||
|
if counter == max(stops):
|
||||||
|
break
|
||||||
|
print 'Values: ', values
|
||||||
|
print 'Product: ', product(values)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in a new issue