Skip to content

[Project Euler] Fix code style in Problem 41 #2992

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

Merged
merged 8 commits into from
Oct 8, 2020

Conversation

jrosellr
Copy link
Contributor

@jrosellr jrosellr commented Oct 7, 2020

Describe your change:

Addresses #2786

  • Improved the problem description with a link
  • Added solution function that calls the old function.
  • Fixed some doctests, their use was inconsistent with the functions they tested

I have some questions @dhruvmanila :

  1. Is it correct to use an assignment inside an f-string? PyCharm is complaining and I can't execute the tests with the current solution call, but I'm leaving it as I found it in the original file.
  2. There is one test case (with n = 7) that is cumbersome to put in a doctest, as the call generates a huge list that wraps around many lines, I have left it out and tested directly the solution output, which passes the test case. Should I leave it as it was and undo the changes?

  • 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}.

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>
Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>
Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>
Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>
@jrosellr jrosellr changed the title Fix problem 41 [Project Euler] Fix code style in Problem 41 Oct 7, 2020
Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>
@dhruvmanila
Copy link
Member

print(f"{max(compute_pandigital_primes(7)) = }")

If you're referring to this then this is not an assignment statement. The = sign in an f-string means that it will produce an output where the expression will be mentioned first then = and then the output of the expression.

Example:

>>> print(f"{1 + 2 = }")
1 + 2 = 3

For 2: leave it as it was

Copy link

@moveax3 moveax3 left a comment

Choose a reason for hiding this comment

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

Good increase of pythonicity and code documentation.

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>
@jrosellr
Copy link
Contributor Author

jrosellr commented Oct 7, 2020

Alright, I removed the extra function I added and left the old code as it was.

@dhruvmanila
Copy link
Member

The answer is actually the maximum value in the list but the function returns a list, we just need the value. Please make the necessary changes as required.

@dhruvmanila dhruvmanila added the awaiting changes A maintainer has requested changes to this PR label Oct 8, 2020
jrosellr and others added 2 commits October 8, 2020 08:38
Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

@dhruvmanila dhruvmanila merged commit 7d54056 into TheAlgorithms:master Oct 8, 2020
@jrosellr jrosellr deleted the fix-problem-41 branch October 8, 2020 08:43
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* add problem title and link, fix f-string

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* fix code style and improve doctests

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* undo changes to the main call

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* remove assignment operator in f-string

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* add newline after first import to attempt to fix pre-commit workflow

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* undo doctest changes, rename compute_pandigital_primes to solution

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* update solution to return the actual solution instead of a list

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* Update sol1.py

Co-authored-by: Dhruv <dhruvmanila@gmail.com>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
* add problem title and link, fix f-string

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* fix code style and improve doctests

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* undo changes to the main call

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* remove assignment operator in f-string

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* add newline after first import to attempt to fix pre-commit workflow

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* undo doctest changes, rename compute_pandigital_primes to solution

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* update solution to return the actual solution instead of a list

Signed-off-by: joan.rosellr <joan.rosellr@gmail.com>

* Update sol1.py

Co-authored-by: Dhruv <dhruvmanila@gmail.com>
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants