File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments