Skip to content

Commit 6a8f1cf

Browse files
Solution to Problem 40
1 parent 9ed60ba commit 6a8f1cf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Project Euler/Problem 40/sol1.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#-.- coding: latin-1 -.-
2+
from __future__ import print_function
3+
'''
4+
Champernowne's constant
5+
Problem 40
6+
An irrational decimal fraction is created by concatenating the positive integers:
7+
8+
0.123456789101112131415161718192021...
9+
10+
It can be seen that the 12th digit of the fractional part is 1.
11+
12+
If dn represents the nth digit of the fractional part, find the value of the following expression.
13+
14+
d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
15+
'''
16+
17+
constant = []
18+
i = 1
19+
20+
while len(constant) < 1e6:
21+
constant.append(str(i))
22+
i += 1
23+
24+
constant = ''.join(constant)
25+
26+
print(int(constant[0])*int(constant[9])*int(constant[99])*int(constant[999])*int(constant[9999])*int(constant[99999])*int(constant[999999]))

0 commit comments

Comments
 (0)