Skip to content

p54 with player info comparison - #59

Merged
dchou1618 merged 2 commits into
masterfrom
feature/p54
Jul 27, 2026
Merged

dchou1618 merged 2 commits into
masterfrom
feature/p54

Conversation

@dchou1618

Copy link
Copy Markdown
Owner

Summary

  • Hand ranking with tie-break logic.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add Project Euler 54 poker-hand ranking with tie-break comparison

✨ Enhancement 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Add a solver for Euler #54 that ranks and compares 5-card poker hands.
• Implement hand categorization with tie-break tuples to resolve same-rank outcomes.
• Add a regression test validating the expected win count on the provided dataset.
Diagram

graph TD
  T["tests/euler/p54_test.py"] --> PH["poker_hands()"] --> DF[("0054_poker.txt")]
  DF --> E["Evaluate hands"] --> C{"Compare ranks"} --> R["Player1 win count"]
  subgraph Legend
    direction LR
    _code["Python module/function"] ~~~ _data[("Data file")] ~~~ _dec{"Decision"}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Simpler straight detection via sorting
  • ➕ Less code and easier to reason about than union-find
  • ➕ Naturally handles duplicates by deduping then checking adjacency
  • ➖ Must explicitly handle A-2-3-4-5 (already handled elsewhere)
2. Rely exclusively on (Rank, tiebreak) tuple comparison
  • ➕ Single consistent comparison path for all ranks
  • ➕ Avoids ad-hoc fallback logic when ranks are equal
  • ➖ Requires ensuring determine_rank() fully encodes all tie-break rules
3. Use Counter + normalized hand model (dataclass/tuple)
  • ➕ Improves readability by separating parsing, normalization, and scoring
  • ➕ Makes future extensions (more tests / additional tie rules) easier
  • ➖ Slightly more structure than needed for a single Euler solution

Recommendation: The overall approach (compute a comparable (Rank, tie-break) score per hand) is the right strategy. Consider simplifying straight detection (sorting-based) and removing the special-case max-card fallback in favor of fully trusting the tie-break tuple, which should make comparisons both clearer and more correct.

Files changed (2) +163 / -0

Enhancement (1) +159 / -0
p54.pyImplement poker hand ranking and comparison for Euler #54 +159/-0

Implement poker hand ranking and comparison for Euler #54

• Adds a hand evaluator that derives suit uniformity, value counts, and straight detection, then maps the hand to a (Rank, tie-break) tuple. Implements a file-driven solver that parses each deal, compares the two players’ ranked outcomes, and counts Player 1 wins.

Algorithms/numerical_methods/euler/p54.py

Tests (1) +4 / -0
p54_test.pyAdd regression test for expected Euler #54 answer +4/-0

Add regression test for expected Euler #54 answer

• Introduces a test that runs the solver against the provided poker dataset and asserts the known result (376 Player 1 wins).

tests/euler/p54_test.py

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Py3.8 annotation import crash 🐞 Bug ≡ Correctness
Description
determine_rank uses tuple[...] in its return annotation, which is not supported on Python 3.8
and can raise TypeError at import time. The project declares requires-python = ">=3.8", so
importing Algorithms.numerical_methods.euler.p54 may fail in supported environments.
Code

Algorithms/numerical_methods/euler/p54.py[76]

+def determine_rank(player_info: Dict[str, Any]) -> tuple[Rank, tuple]:
Relevance

⭐⭐⭐ High

Repo accepts type-annotation fixes; Python 3.8 import-time TypeError is a clear correctness issue.

PR-#55

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The module uses a PEP585 built-in generic annotation at function definition time, while the project
explicitly supports Python 3.8 where tuple[...] is not valid without postponed annotation
evaluation.

Algorithms/numerical_methods/euler/p54.py[76-76]
pyproject.toml[5-11]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`Algorithms/numerical_methods/euler/p54.py` uses PEP585 built-in generic syntax (`tuple[Rank, tuple]`) in a type annotation. On Python 3.8 this can crash at import time because built-in `tuple` is not subscriptable for annotations unless annotations are postponed.

### Issue Context
The repository supports Python 3.8 (`requires-python = ">=3.8"`).

### Fix Focus Areas
- Algorithms/numerical_methods/euler/p54.py[76-76]
- pyproject.toml[5-11]

### Suggested fix
Change the return type to a 3.8-compatible annotation, e.g.:
- `from typing import Tuple` and `-> Tuple[Rank, tuple]`, or
- add `from __future__ import annotations` at the top and keep the current syntax, or
- use a string annotation: `-> "tuple[Rank, tuple]"`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Missing poker dataset in test 🐞 Bug ☼ Reliability
Description
The new test calls poker_hands("Algorithms/numerical_methods/euler/data/0054_poker.txt"), but the
PR does not add this dataset; poker_hands opens the path directly, so the test will raise
FileNotFoundError in CI checkouts without that file. This blocks the new test from running
deterministically.
Code

tests/euler/p54_test.py[R1-4]

+from Algorithms.numerical_methods.euler.p54 import poker_hands
+
+def test_p54():
+    assert poker_hands("Algorithms/numerical_methods/euler/data/0054_poker.txt") == 376
Relevance

⭐⭐⭐ High

Team has accepted CI/test reliability fixes; missing fixture data would fail deterministically in
CI.

PR-#35

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The test hardcodes a dataset path, and poker_hands immediately opens whatever path it receives
with no fallback, so absence of the file causes an exception instead of a deterministic test result.

tests/euler/p54_test.py[1-4]
Algorithms/numerical_methods/euler/p54.py[144-148]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`tests/euler/p54_test.py` depends on an external data file (`Algorithms/numerical_methods/euler/data/0054_poker.txt`) that is not introduced by this PR. The implementation opens the provided filename directly, so tests will fail if the data file is missing.

### Issue Context
Unit tests should be self-contained: either commit the required fixture into the repo or embed a minimal sample in the test and/or parameterize `poker_hands` to accept an iterable of lines.

### Fix Focus Areas
- tests/euler/p54_test.py[1-4]
- Algorithms/numerical_methods/euler/p54.py[144-148]

### Suggested fix options
1) Add the missing dataset file under `Algorithms/numerical_methods/euler/data/0054_poker.txt` to the repo, or
2) Change `poker_hands` to accept file-like/iterable input and update the test to pass an in-test fixture (e.g., `io.StringIO`) with a small deterministic set of hands that asserts expected wins.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. No trailing newline in test 🐞 Bug ⚙ Maintainability
Description
tests/euler/p54_test.py is added without a trailing newline, which can cause formatting/tooling
churn and noisy diffs. Add a final newline at end-of-file.
Code

tests/euler/p54_test.py[R1-4]

+from Algorithms.numerical_methods.euler.p54 import poker_hands
+
+def test_p54():
+    assert poker_hands("Algorithms/numerical_methods/euler/data/0054_poker.txt") == 376
Relevance

⭐⭐⭐ High

Exact precedent: trailing newline fix was accepted to avoid noisy diffs; same issue in new test.

PR-#54

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
A prior accepted bug fix in this repo explicitly addressed missing trailing newlines; this PR
introduces the same pattern in the new test file.

tests/euler/p54_test.py[1-4]
PR-#49

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The newly added `tests/euler/p54_test.py` has no trailing newline at EOF.

### Issue Context
This repo has previously addressed the same formatting issue to avoid diff noise.

### Fix Focus Areas
- tests/euler/p54_test.py[1-4]

### Suggested fix
Ensure the file ends with a newline character (POSIX newline at EOF).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

"all_consecutive": all_consecutive
}

def determine_rank(player_info: Dict[str, Any]) -> tuple[Rank, tuple]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Py3.8 annotation import crash 🐞 Bug ≡ Correctness

determine_rank uses tuple[...] in its return annotation, which is not supported on Python 3.8
and can raise TypeError at import time. The project declares requires-python = ">=3.8", so
importing Algorithms.numerical_methods.euler.p54 may fail in supported environments.
Agent Prompt
### Issue description
`Algorithms/numerical_methods/euler/p54.py` uses PEP585 built-in generic syntax (`tuple[Rank, tuple]`) in a type annotation. On Python 3.8 this can crash at import time because built-in `tuple` is not subscriptable for annotations unless annotations are postponed.

### Issue Context
The repository supports Python 3.8 (`requires-python = ">=3.8"`).

### Fix Focus Areas
- Algorithms/numerical_methods/euler/p54.py[76-76]
- pyproject.toml[5-11]

### Suggested fix
Change the return type to a 3.8-compatible annotation, e.g.:
- `from typing import Tuple` and `-> Tuple[Rank, tuple]`, or
- add `from __future__ import annotations` at the top and keep the current syntax, or
- use a string annotation: `-> "tuple[Rank, tuple]"`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread tests/euler/p54_test.py
Comment on lines +1 to +4
from Algorithms.numerical_methods.euler.p54 import poker_hands

def test_p54():
assert poker_hands("Algorithms/numerical_methods/euler/data/0054_poker.txt") == 376 No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. Missing poker dataset in test 🐞 Bug ☼ Reliability

The new test calls poker_hands("Algorithms/numerical_methods/euler/data/0054_poker.txt"), but the
PR does not add this dataset; poker_hands opens the path directly, so the test will raise
FileNotFoundError in CI checkouts without that file. This blocks the new test from running
deterministically.
Agent Prompt
### Issue description
`tests/euler/p54_test.py` depends on an external data file (`Algorithms/numerical_methods/euler/data/0054_poker.txt`) that is not introduced by this PR. The implementation opens the provided filename directly, so tests will fail if the data file is missing.

### Issue Context
Unit tests should be self-contained: either commit the required fixture into the repo or embed a minimal sample in the test and/or parameterize `poker_hands` to accept an iterable of lines.

### Fix Focus Areas
- tests/euler/p54_test.py[1-4]
- Algorithms/numerical_methods/euler/p54.py[144-148]

### Suggested fix options
1) Add the missing dataset file under `Algorithms/numerical_methods/euler/data/0054_poker.txt` to the repo, or
2) Change `poker_hands` to accept file-like/iterable input and update the test to pass an in-test fixture (e.g., `io.StringIO`) with a small deterministic set of hands that asserts expected wins.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread tests/euler/p54_test.py
Comment on lines +1 to +4
from Algorithms.numerical_methods.euler.p54 import poker_hands

def test_p54():
assert poker_hands("Algorithms/numerical_methods/euler/data/0054_poker.txt") == 376 No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Informational

3. No trailing newline in test 🐞 Bug ⚙ Maintainability

tests/euler/p54_test.py is added without a trailing newline, which can cause formatting/tooling
churn and noisy diffs. Add a final newline at end-of-file.
Agent Prompt
### Issue description
The newly added `tests/euler/p54_test.py` has no trailing newline at EOF.

### Issue Context
This repo has previously addressed the same formatting issue to avoid diff noise.

### Fix Focus Areas
- tests/euler/p54_test.py[1-4]

### Suggested fix
Ensure the file ends with a newline character (POSIX newline at EOF).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@dchou1618
dchou1618 merged commit a69129c into master Jul 27, 2026
5 checks passed
@dchou1618
dchou1618 deleted the feature/p54 branch July 27, 2026 04:35
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.

1 participant