-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path040.py
More file actions
38 lines (26 loc) · 952 Bytes
/
Copy path040.py
File metadata and controls
38 lines (26 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Problem 40
==========
An irrational decimal fraction is created by concatenating the positive
integers:
0.123456789101112131415161718192021...
It can be seen that the 12^th digit of the fractional part is 1.
If d[n] represents the n^th digit of the fractional part, find the value
of the following expression.
d[1] × d[10] × d[100] × d[1000] × d[10000] × d[100000] × d[1000000]
Answer: 6f3ef77ac0e3619e98159e9b6febf557
"""
from common import check
from itertools import takewhile, count
PROBLEM_NUMBER = 40
ANSWER_HASH = "6f3ef77ac0e3619e98159e9b6febf557"
def generate():
for i in count(1):
for c in str(i):
yield int(c)
def d(n):
for i, v in enumerate(generate()):
if i >= n - 1:
return v
result = d(1) * d(10) * d(100) * d(1000) * d(10000) * d(100000) * d(1000000)
check(result, PROBLEM_NUMBER, ANSWER_HASH)