Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
maths/gcd_of_n_numbers.py
Outdated
| if factors is None: | ||
| # first call of get factors and so there are no founded factors | ||
| factors = Counter() |
There was a problem hiding this comment.
All falsey values are as dangerous as None.
| if factors is None: | |
| # first call of get factors and so there are no founded factors | |
| factors = Counter() | |
| factors = factors or Counter() |
maths/gcd_of_n_numbers.py
Outdated
| return factors | ||
|
|
||
| if number % factor > 0: | ||
| # if it is grater than zero |
There was a problem hiding this comment.
| # if it is grater than zero | |
| # if it is greater than zero |
There was a problem hiding this comment.
Thank you, updated... please check and let me know if there are any problems
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
|
@algorithms-keeper review |
maths/gcd_of_n_numbers.py
Outdated
|
|
||
| same_factors: Counter = data[0] | ||
| for d in data[1:]: | ||
| same_factors = same_factors & d |
There was a problem hiding this comment.
| same_factors = same_factors & d | |
| same_factors &= d |
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
maths/gcd_of_n_numbers.py
Outdated
| # now, same_factors is something like {2: 2, 3: 4} that means 2 * 2 * 3 * 3 * 3 * 3 | ||
| # power each factor and multiply | ||
| # for {2: 2, 3: 4}, it is [4, 81] and then 324 | ||
| return reduce(lambda x, y: x * y, (factor ** power for factor, power in same_factors.items()), 1) |
There was a problem hiding this comment.
Please provide descriptive name for the parameter: x
Please provide descriptive name for the parameter: y
for more information, see https://pre-commit.ci
| # we just need factors, not numbers itself | ||
| try: | ||
| data = [get_factors(number) for number in numbers] | ||
| same_factors, *factors = map(get_factors, numbers) |
There was a problem hiding this comment.
https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md#coding-style
List comprehensions and generators are preferred over the use of
lambda,map,filter,reduce
https://docs.python.org/3/whatsnew/3.0.html#views-and-iterators-instead-of-lists
maths/gcd_of_n_numbers.py
Outdated
| for m in [factor ** same_factors[factor] for factor in same_factors]: | ||
| mult *= m | ||
| return mult | ||
| return reduce(lambda x, y: x * y, (factor ** power for factor, power in same_factors.items())) |
There was a problem hiding this comment.
This is going to be hard to understand and maintain.
for more information, see https://pre-commit.ci
* add maths/Gcd of N Numbers * add maths/Gcd of N Numbers * add maths/Gcd of N Numbers * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add maths/Gcd of N Numbers * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add maths/Gcd of N Numbers * add maths/Gcd of N Numbers * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add maths/Gcd of N Numbers * add maths/Gcd of N Numbers * more pythonic * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * more pythonic * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * merged * merged * more readable * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Describe your change:
Greatest common divisor for n numbers
Checklist:
Fixes: #{$ISSUE_NO}.