-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Added problem 66 to project_euler #3388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
|
|
||
| Project Euler 66 | ||
| https://projecteuler.net/problem=66 | ||
| https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Algorithm | ||
|
|
||
|
|
||
| Consider quadratic Diophantine equations of the form: | ||
|
|
||
| x^2 – Dy^2 = 1 | ||
|
|
||
| For example, when D=13, the minimal | ||
| solution in x is 6492 – 13×1802 = 1. | ||
|
|
||
| It can be assumed that there are no solutions in | ||
| positive integers when D is square. | ||
|
|
||
| By finding minimal solutions in x for | ||
| D = {2, 3, 5, 6, 7}, we obtain the following: | ||
|
|
||
| 3^2 – 2×2^2 = 1 | ||
| 2^2 – 3×1^2 = 1 | ||
| 9^2 – 5×4^2 = 1 | ||
| 5^2 – 6×2^2 = 1 | ||
| 8^2 – 7×3^2 = 1 | ||
|
|
||
| Hence, by considering minimal solutions in x for D ≤ 7, | ||
| the largest x is obtained when D=5. | ||
|
|
||
| Find the value of D ≤ 1000 in minimal solutions of | ||
| x for which the largest value of x is obtained. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Project Euler 66 | |
| https://projecteuler.net/problem=66 | |
| https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Algorithm | |
| Consider quadratic Diophantine equations of the form: | |
| x^2 – Dy^2 = 1 | |
| For example, when D=13, the minimal | |
| solution in x is 6492 – 13×1802 = 1. | |
| It can be assumed that there are no solutions in | |
| positive integers when D is square. | |
| By finding minimal solutions in x for | |
| D = {2, 3, 5, 6, 7}, we obtain the following: | |
| 3^2 – 2×2^2 = 1 | |
| 2^2 – 3×1^2 = 1 | |
| 9^2 – 5×4^2 = 1 | |
| 5^2 – 6×2^2 = 1 | |
| 8^2 – 7×3^2 = 1 | |
| Hence, by considering minimal solutions in x for D ≤ 7, | |
| the largest x is obtained when D=5. | |
| Find the value of D ≤ 1000 in minimal solutions of | |
| x for which the largest value of x is obtained. | |
| Project Euler problem 66: https://projecteuler.net/problem=66 | |
| Consider quadratic Diophantine equations of the form: | |
| x^2 – Dy^2 = 1 | |
| For example, when D=13, the minimal | |
| solution in x is 6492 – 13×1802 = 1. | |
| It can be assumed that there are no solutions in | |
| positive integers when D is square. | |
| By finding minimal solutions in x for | |
| D = {2, 3, 5, 6, 7}, we obtain the following: | |
| 3^2 – 2×2^2 = 1 | |
| 2^2 – 3×1^2 = 1 | |
| 9^2 – 5×4^2 = 1 | |
| 5^2 – 6×2^2 = 1 | |
| 8^2 – 7×3^2 = 1 | |
| Hence, by considering minimal solutions in x for D ≤ 7, | |
| the largest x is obtained when D=5. | |
| Find the value of D ≤ 1000 in minimal solutions of | |
| x for which the largest value of x is obtained. | |
| References: | |
| - https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Algorithm |
| def continued_fraction(n: int) -> list: | ||
|
|
||
| """ | ||
| function to find continued fraction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better description of what the function does.
| mn = 0.0 | ||
| dn = 1.0 | ||
| a0 = int(sqrt(n)) | ||
| an = int(sqrt(n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Descriptive variable names, please.
| a0 = int(sqrt(n)) | ||
| an = int(sqrt(n)) | ||
| convergents = [a0] | ||
| # period = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary. Please remove it.
| return convergents[:-1] | ||
|
|
||
|
|
||
| def simple_frac(cf: list()) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Descriptive function and parameter name.
Proper type hints needed: https://docs.python.org/3/library/typing.html
|
|
||
| """ | ||
| function to find value of D in minimal solutions of x | ||
| for which x is largest. | ||
| """ | ||
| """ | ||
| >>> solution(7) | ||
| 5 | ||
|
|
||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """ | |
| function to find value of D in minimal solutions of x | |
| for which x is largest. | |
| """ | |
| """ | |
| >>> solution(7) | |
| 5 | |
| """ | |
| """ | |
| function to find value of D in minimal solutions of x | |
| for which x is largest. | |
| >>> solution(7) | |
| 5 | |
| """ |
A better description of what the function does.
Need more doctest
| u, v = simple_frac(continued_frac) | ||
| u = 2 * u ** 2 + 1 | ||
| v = 2 * u * v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Descriptive variable names
| # for loop less than 1000 | ||
| for i in range(1, limit): | ||
| if i % sqrt(i) != 0: | ||
| # print("cc",i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary. Please remove it.
| import doctest | ||
|
|
||
| doctest.testmod() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed.
| import doctest | ||
|
|
||
| doctest.testmod() | ||
| print(f"{solution()}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| print(f"{solution()}") | |
| print(f"{solution() = }") |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions! |


Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.