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

Create problem_54 in project Euler #2451

Merged
merged 7 commits into from
Sep 20, 2020
Merged

Conversation

dhruvmanila
Copy link
Member

Add solution and test files (in pytest) for project Euler problem 54

There are a couple of extra features of the PokerHand class:

  • A public method PokerHand.hand_name() which returns the name of hand as stated in the Wikipedia link
  • Added rich comparison operators such as <, >, <=, >=, ==, != and this in turn gives us the ability to use the builtin sort method and sorted function on a list of PokerHand objects.

The test file test_poker_hand.py should be picked up by Travis and it checks every function of sol1.py through pytest.

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

@dhruvmanila
Copy link
Member Author

Hi, I'll fix the codespell errors.

What does this codespell comment trying to say?

'project_euler/problem_54/test_poker_hand.py': [(209, 'ans', 'and'), (217, 'ans', 'and'), (218, 'ans', 'and')]}

Should I change the variable named ans to something more verbose like answer? This variable is in test_poker_hand.py file.

- Use list comprehension instead of map
- Sort imports using isort
@cclauss
Copy link
Member

cclauss commented Sep 19, 2020

Should I change the variable named ans to something more verbose like answer?

Yes.

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

This is so cool!

project_euler/problem_54/sol1.py Outdated Show resolved Hide resolved
project_euler/problem_54/test_poker_hand.py Outdated Show resolved Hide resolved
project_euler/problem_54/test_poker_hand.py Outdated Show resolved Hide resolved
project_euler/problem_54/test_poker_hand.py Outdated Show resolved Hide resolved
project_euler/problem_54/test_poker_hand.py Outdated Show resolved Hide resolved
project_euler/problem_54/test_poker_hand.py Outdated Show resolved Hide resolved
project_euler/problem_54/test_poker_hand.py Outdated Show resolved Hide resolved
- List and set comprehension instead of itemgetter
- Using enumerate as it's easy to read
- Divided into list of card values and set of card suit as set will
  remove all the duplicate values. So, no need for double indexing.
- Add test for testing multiple calls to five_high_straight function
- Split generate_random_hands function into two:
  - First will generate a random hand
  - Second, which will be called, will return a generator object
@cclauss cclauss merged commit ea0759d into TheAlgorithms:master Sep 20, 2020
@cclauss
Copy link
Member

cclauss commented Sep 20, 2020

An awesome contribution! Thanks for doing this.

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Add solution and test files for project euler 54

* Update sol1.py

* updating DIRECTORY.md

* Fix: use proper path to open files

* Commit suggestions:

- Use list comprehension instead of map
- Sort imports using isort

* Changes made as suggested (simplified a lot):

- List and set comprehension instead of itemgetter
- Using enumerate as it's easy to read
- Divided into list of card values and set of card suit as set will
  remove all the duplicate values. So, no need for double indexing.
- Add test for testing multiple calls to five_high_straight function

* Add suggestions and simplified:

- Split generate_random_hands function into two:
  - First will generate a random hand
  - Second, which will be called, will return a generator object

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants