Skip to content

Commit c4338f3

Browse files
committed
solved 040
1 parent c86e20c commit c4338f3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

euler_040.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Champernowne
2+
# An irrational decimal fraction is created by concatenating the positive integers:
3+
#
4+
# 0.123456789101112131415161718192021...
5+
#
6+
# It can be seen that the 12th digit of the fractional part is 1.
7+
#
8+
# If dn represents the nth digit of the fractional part, find the value of the following expression.
9+
#
10+
# d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
11+
12+
def champernowne():
13+
i = 1
14+
while True:
15+
digits = str(i)
16+
for d in digits:
17+
yield int(d)
18+
i += 1
19+
20+
keepers = []
21+
prod = i = 1
22+
for d in champernowne():
23+
if i == 1 or i == 10 or i == 100 or i == 1000 or i == 10000 or i == 100000 or i == 1000000:
24+
keepers.append(d)
25+
prod *= d
26+
if i == 1000000:
27+
break
28+
i += 1
29+
print(keepers)
30+
print(prod)

0 commit comments

Comments
 (0)