Skip to content
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

Removed redundant greatest_common_divisor code #9358

Merged
merged 12 commits into from
Oct 9, 2023

Conversation

Siddikpatel
Copy link
Contributor

Describe your change:

Previously all the files that needed greatest_common_divisor (aka gcd), used to define the method instead of just importing from Maths directory's greatest_common_divisor.py file. I removed thos definitions and imported gcd method from Maths folder. Fixes #8098

  • 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 include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Oct 2, 2023
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 2, 2023
@Siddikpatel
Copy link
Contributor Author

It says organize imports. Don't know what to do about that. Otherwise there are no issues

@tianyizheng02
Copy link
Contributor

@Siddikpatel Please run ruff --fix . locally to have ruff auto-sort the imports

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 8, 2023
@Siddikpatel
Copy link
Contributor Author

Fixed the import issues!

maths/greatest_common_divisor.py Outdated Show resolved Hide resolved
maths/greatest_common_divisor.py Outdated Show resolved Hide resolved
@tianyizheng02
Copy link
Contributor

I just remembered that the Python math module already has a gcd function. @cclauss, do you think it's better for our files to simply import gcd from math? Or is it better for our files to use our own implementation?

@tianyizheng02
Copy link
Contributor

BTW, @Siddikpatel, there are even more duplicate implementations of gcd if you search for "gcd" in the repo (for example, in maths/carmichael_number.py), so those could be removed as well

@Siddikpatel
Copy link
Contributor Author

BTW, @Siddikpatel, there are even more duplicate implementations of gcd if you search for "gcd" in the repo (for example, in maths/carmichael_number.py), so those could be removed as well

and, what about those files that imports gcd from math module of python?

@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Oct 8, 2023
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Oct 8, 2023
@cclauss cclauss enabled auto-merge (squash) October 8, 2023 05:09
@tianyizheng02
Copy link
Contributor

and, what about those files that imports gcd from math module of python?

Those are fine—it's fine to import functions as helper functions as long as it doesn't include the core of the actual algorithm

Copy link
Contributor

@tianyizheng02 tianyizheng02 left a comment

Choose a reason for hiding this comment

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

Looks good, but the merge conflict will need to be fixed. I can't fix it myself because I don't have write permission, so could you fix it?

maths/carmichael_number.py Outdated Show resolved Hide resolved
@algorithms-keeper algorithms-keeper bot added merge conflicts Open a new PR or rebase on the latest commit awaiting reviews This PR is ready to be reviewed labels Oct 8, 2023
auto-merge was automatically disabled October 9, 2023 02:13

Head branch was pushed to by a user without write access

@Siddikpatel
Copy link
Contributor Author

Looks good, but the merge conflict will need to be fixed. I can't fix it myself because I don't have write permission, so could you fix it?

Ok I am confused now.. It says merge conflicts in modular_division.py.

@tianyizheng02
Copy link
Contributor

OK, I see what happened: a previous PR moved blockchain/modular__division.py to the maths directory, and that's causing a merge conflict here because you still have the file in the blockchain directory. I'm guessing that the conflict will be resolved if you move the file to the maths directory as well?

@Siddikpatel
Copy link
Contributor Author

Yup, it is fixed now.

@tianyizheng02
Copy link
Contributor

It says the file was deleted... did you not move it into the maths module?

@Siddikpatel
Copy link
Contributor Author

It says the file was deleted... did you not move it into the maths module?

I've moved it to maths directory.
Screenshot (160)

@cclauss cclauss merged commit 583a614 into TheAlgorithms:master Oct 9, 2023
5 checks passed
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Oct 9, 2023
@quant12345
Copy link
Contributor

quant12345 commented Oct 9, 2023

@tianyizheng02 @cclauss A couple of days ago carmichael_number - add doctests. Do I need to delete this pull request (in 'Files changed' there is gcd)? At the bottom there was an inscription about a merge conflict. I made edits taking into account greatest_common_divisor. Now there is no warning. But will there be problems if there is a merger?

@tianyizheng02
Copy link
Contributor

No, there shouldn't be any problems. This PR has already been merged so it can't be "deleted" anyway. For your other PR, GitHub will merge it into the updated codebase, the one with this PR already merged.

sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this pull request Sep 15, 2024
* Deleted greatest_common_divisor def from many files and instead imported the method from Maths folder

* Deleted greatest_common_divisor def from many files and instead imported the method from Maths folder, also fixed comments

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Deleted greatest_common_divisor def from many files and instead imported the method from Maths folder, also fixed comments

* Imports organized

* recursive gcd function implementation rolledback

* more gcd duplicates removed

* more gcd duplicates removed

* Update maths/carmichael_number.py

* updated files

* moved a file to another location

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files merge conflicts Open a new PR or rebase on the latest commit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Concatenate/consolidate all algorithms with different implementations
4 participants