The Wayback Machine - https://web.archive.org/web/20250603205952/https://github.com/TheAlgorithms/Python/pull/3388
Skip to content

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

Closed

Conversation

Kalyani123kumari
Copy link

@Kalyani123kumari Kalyani123kumari commented Oct 16, 2020

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
Comment on lines +2 to +33


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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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^2Dy^2 = 1
For example, when D=13, the minimal
solution in x is 649213×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^22×2^2 = 1
2^23×1^2 = 1
9^25×4^2 = 1
5^26×2^2 = 1
8^27×3^2 = 1
Hence, by considering minimal solutions in x for D7,
the largest x is obtained when D=5.
Find the value of D1000 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^2Dy^2 = 1
For example, when D=13, the minimal
solution in x is 649213×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^22×2^2 = 1
2^23×1^2 = 1
9^25×4^2 = 1
5^26×2^2 = 1
8^27×3^2 = 1
Hence, by considering minimal solutions in x for D7,
the largest x is obtained when D=5.
Find the value of D1000 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
Copy link
Member

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.

Comment on lines +57 to +60
mn = 0.0
dn = 1.0
a0 = int(sqrt(n))
an = int(sqrt(n))
Copy link
Member

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
Copy link
Member

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:
Copy link
Member

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

Comment on lines +97 to +106

"""
function to find value of D in minimal solutions of x
for which x is largest.
"""
"""
>>> solution(7)
5

"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""
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

Comment on lines +116 to +118
u, v = simple_frac(continued_frac)
u = 2 * u ** 2 + 1
v = 2 * u * v
Copy link
Member

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)
Copy link
Member

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.

Comment on lines +129 to +131
import doctest

doctest.testmod()
Copy link
Member

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()}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(f"{solution()}")
print(f"{solution() = }")
@dhruvmanila dhruvmanila added awaiting changes A maintainer has requested changes to this PR Do not meet Solution Guidelines labels Oct 25, 2020
@stale
Copy link

stale bot commented Nov 24, 2020

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.

@stale stale bot added the stale Used to mark an issue or pull request stale. label Nov 24, 2020
@stale
Copy link

stale bot commented Dec 1, 2020

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!

@stale stale bot closed this Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes A maintainer has requested changes to this PR stale Used to mark an issue or pull request stale.
3 participants