Skip to content

Commit 2459cfd

Browse files
author
Srishtik2310
committed
Changed documentation and formatting.
1 parent 32e611f commit 2459cfd

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

project_euler/problem_686/sol1.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
22
Project Euler Problem 686: https://projecteuler.net/problem=686
33
4-
2**7 = 128 is the first power of two whose leading digits are "12".
5-
The next power of two whose leading digits are "12" is 2**80.
4+
2^7 = 128 is the first power of two whose leading digits are "12".
5+
The next power of two whose leading digits are "12" is 2^80.
66
77
Define p(L,n) to be the nth-smallest value of j such that
8-
the base 10 representation of 2**j begins with the digits of L.
8+
the base 10 representation of 2^j begins with the digits of L.
99
1010
So p(12, 1) = 7 and p(12, 2) = 80.
1111
@@ -24,8 +24,8 @@ def log_difference(number: int) -> float:
2424
large exponents is time consuming. Hence we use log to reduce compute time.
2525
2626
We can find out that the first power of 2 with starting digits 123 is 90.
27-
Computing 2**90 is time consuming.
28-
Hence we find log(2**90) = 90*log(2) = 27.092699609758302
27+
Computing 2^90 is time consuming.
28+
Hence we find log(2^90) = 90*log(2) = 27.092699609758302
2929
But we require only the decimal part to determine whether the power starts with 123.
3030
SO we just return the decimal part of the log product.
3131
Therefore we return 0.092699609758302
@@ -43,14 +43,11 @@ def log_difference(number: int) -> float:
4343
return difference
4444

4545

46-
# series = 90, 379, 575, 864, 1060, 1545, 1741, 2030, 2226, 2515
47-
48-
4946
def solution(number: int = 678910) -> int:
5047
"""
5148
This function calculates the power of two which is nth (n = number)
5249
smallest value of power of 2
53-
such that the starting digits of the 2**power is 123.
50+
such that the starting digits of the 2^power is 123.
5451
5552
For example the powers of 2 for which starting digits is 123 are:
5653
90, 379, 575, 864, 1060, 1545, 1741, 2030, 2226, 2515 and so on.
@@ -64,7 +61,7 @@ def solution(number: int = 678910) -> int:
6461
lowerbound = log(1.23), upperbound = log(1.24)
6562
because we need to find the powers that yield 123 as starting digits.
6663
67-
log(1.23) = 08990511143939792, log(1,24) = 09342168516223506.
64+
log(1.23) = 0.08990511143939792, log(1,24) = 0.09342168516223506.
6865
We use 1.23 and not 12.3 or 123, because log(1.23) yields only decimal value
6966
which is less than 1.
7067
log(12.3) will be same decimal vale but 1 added to it

0 commit comments

Comments
 (0)