Skip to content

feat(math): power of three#200

Merged
BrianLusina merged 4 commits into
mainfrom
feat/power-of-three
Jun 22, 2026
Merged

feat(math): power of three#200
BrianLusina merged 4 commits into
mainfrom
feat/power-of-three

Conversation

@BrianLusina

@BrianLusina BrianLusina commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Describe your change:

This shows 3 variations to the problem to solve for whether an integer is a power of three

  • Add an algorithm?
  • [x ] 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}.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added power of three checking functionality with multiple algorithmic approaches available.
  • Bug Fixes

    • Corrected imaginary unit notation in existing documentation.
  • Documentation

    • Added comprehensive documentation for power of three functionality, including problem definition and solution strategies.
    • Updated directory index.
  • Tests

    • Added unit tests for power of three functionality.

BrianLusina and others added 2 commits June 22, 2026 09:28
This shows 3 variations to th problem
@BrianLusina BrianLusina self-assigned this Jun 22, 2026
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@BrianLusina, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 minutes and 59 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4e7a5ffd-f328-4f6f-871d-4c18cc81a782

📥 Commits

Reviewing files that changed from the base of the PR and between 3b89f07 and 35d473e.

📒 Files selected for processing (1)
  • pymath/power_of_i/README.md
📝 Walkthrough

Walkthrough

Adds a new pymath/power_of_three package with three implementations (log, mod, loop) for checking whether an integer is a power of three, a full README covering all three approaches, and a parameterised unit test suite. Also fixes a typo (iiii) in the existing power_of_i README and registers the new module in DIRECTORY.md.

Changes

Power of Three Module

Layer / File(s) Summary
Three implementations and README
pymath/power_of_three/__init__.py, pymath/power_of_three/README.md
Adds is_power_of_three_with_log, is_power_of_three_with_mod, and is_power_of_three_with_loop to the module. The README documents all three strategies (modulo against 3^19, iterative division, and logarithm-based integrality check) with examples, constraints, and time/space complexity notes.
Parameterised unit tests
pymath/power_of_three/test_power_of_three.py
Defines a shared POWER_OF_THREE_TEST_CASES list and a unittest.TestCase subclass with three parameterized.expand test methods — one per implementation — covering positive powers, non-powers, zero, and negative values.
DIRECTORY entry and power_of_i README fix
DIRECTORY.md, pymath/power_of_i/README.md
Registers Power Of Three under the Pymath section in DIRECTORY.md. Corrects the imaginary unit label from iii to i in the power_of_i problem description.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Three to the power, I hop and I check,
With logs and with loops, I keep things in spec,
Divide by three? Simple — just peel off each layer,
Mod 1162261467? Even fairer!
The rabbit approves — the maths is quite neat. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(math): power of three' clearly and concisely summarizes the main change—adding a power of three algorithm implementation.
Description check ✅ Passed The PR description follows the template structure with most required checklist items completed, though URLs for algorithm explanation are unchecked as noted in the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/power-of-three

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (3)
pymath/power_of_three/README.md (1)

40-48: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add a reference URL for the algorithm explanation.

Please add a short source link (for example, a maths/reference page) near the solution section so the derivation is externally traceable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pymath/power_of_three/README.md` around lines 40 - 48, Add a source reference
URL near the "Using Modulo" solution section in the README to make the algorithm
derivation externally traceable. Include a short reference link (such as a
mathematics or algorithm reference page) that explains the mathematical
reasoning behind why 3^19 is the largest power of 3 within the 32-bit signed
integer range and how divisibility relates to identifying powers of 3. This
should be placed after the solution explanation to provide readers with external
validation of the approach.
pymath/power_of_three/test_power_of_three.py (1)

10-19: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add boundary cases for the 32-bit limit.

Consider extending POWER_OF_THREE_TEST_CASES with 1162261467 (True) and nearby values like 1162261466 / 1162261468 (False) to lock in edge behaviour.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pymath/power_of_three/test_power_of_three.py` around lines 10 - 19, The
POWER_OF_THREE_TEST_CASES needs to include boundary cases for the 32-bit limit
to ensure the power of three detection handles edge cases correctly. Add three
test cases to the list: the value 1162261467 which should return True as it is
the maximum power of three within 32-bit signed integer range, and the values
1162261466 and 1162261468 which should both return False as they are just below
and above this boundary respectively. These additions will verify that the
implementation correctly handles the upper boundary condition.
pymath/power_of_three/__init__.py (1)

13-17: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Clarify the 32-bit assumption in the modulo variant.

This method is constraint-specific (3^19 bound). Add a docstring or explicit guard so callers don’t treat it as a general integer-power check.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pymath/power_of_three/__init__.py` around lines 13 - 17, The function
`is_power_of_three_with_mod` lacks documentation about its constraint to 32-bit
signed integers. Add a comprehensive docstring to this function that explicitly
states it only works for numbers within the 32-bit signed integer range and will
not correctly handle numbers outside this range. Explain that the hardcoded
value 1162261467 represents 3^19, which is the largest power of 3 within 32-bit
bounds, and make clear this is a performance-optimized variant with specific
limitations rather than a general solution for checking arbitrary integer powers
of three.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pymath/power_of_i/README.md`:
- Line 5: The README.md file on line 5 contains a typo where "iii" should be
replaced with "i" to match the actual implementation. In the sentence describing
the pofi function task, change "returns iii to the power of" to "returns i to
the power of" so that the documentation correctly describes that the function
returns the imaginary unit i (not iii) raised to a given power.
- Line 3: On line 3 of README.md, fix the duplicated equation formatting by
removing the redundant representations of the equations so that only a single
clean version of "i²=−1" and "x²+1=0" appear in the text. Additionally, correct
the grammar error in the phrase "therefore it is a solution" by restructuring
the sentence to use proper grammar, such as adding a semicolon before
"therefore" or rephrasing the sentence to use "Thus," or "...and is therefore a
solution to..." to ensure correct grammatical usage.

In `@pymath/power_of_three/README.md`:
- Line 14: The mathematical expressions in the README.md file use incorrect
notation for exponents. Replace `33` with `3^3` on line 14 to properly show
three raised to the power of three. Replace `3x` with `3^x` on lines 21 and 28
to use correct exponent notation throughout. Additionally, remove the stray
trailing backtick on line 21 that appears after one of the expressions. These
changes ensure consistent and correct mathematical notation across all examples
in the file.

---

Nitpick comments:
In `@pymath/power_of_three/__init__.py`:
- Around line 13-17: The function `is_power_of_three_with_mod` lacks
documentation about its constraint to 32-bit signed integers. Add a
comprehensive docstring to this function that explicitly states it only works
for numbers within the 32-bit signed integer range and will not correctly handle
numbers outside this range. Explain that the hardcoded value 1162261467
represents 3^19, which is the largest power of 3 within 32-bit bounds, and make
clear this is a performance-optimized variant with specific limitations rather
than a general solution for checking arbitrary integer powers of three.

In `@pymath/power_of_three/README.md`:
- Around line 40-48: Add a source reference URL near the "Using Modulo" solution
section in the README to make the algorithm derivation externally traceable.
Include a short reference link (such as a mathematics or algorithm reference
page) that explains the mathematical reasoning behind why 3^19 is the largest
power of 3 within the 32-bit signed integer range and how divisibility relates
to identifying powers of 3. This should be placed after the solution explanation
to provide readers with external validation of the approach.

In `@pymath/power_of_three/test_power_of_three.py`:
- Around line 10-19: The POWER_OF_THREE_TEST_CASES needs to include boundary
cases for the 32-bit limit to ensure the power of three detection handles edge
cases correctly. Add three test cases to the list: the value 1162261467 which
should return True as it is the maximum power of three within 32-bit signed
integer range, and the values 1162261466 and 1162261468 which should both return
False as they are just below and above this boundary respectively. These
additions will verify that the implementation correctly handles the upper
boundary condition.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5432f4e8-012c-45eb-ad6f-956a23ab9d4f

📥 Commits

Reviewing files that changed from the base of the PR and between bca596f and 3b89f07.

📒 Files selected for processing (5)
  • DIRECTORY.md
  • pymath/power_of_i/README.md
  • pymath/power_of_three/README.md
  • pymath/power_of_three/__init__.py
  • pymath/power_of_three/test_power_of_three.py

Comment thread pymath/power_of_i/README.md Outdated
Comment thread pymath/power_of_i/README.md Outdated
```text
Input: n = 27
Output: true
Explanation: 27 = 33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix mathematical notation and punctuation in the examples.

Line 14 (27 = 33) and Lines 21/28 (3x) should use exponent notation (e.g., 3^3, 3^x), and Line 21 has a stray trailing backtick.

Also applies to: 21-21, 28-28

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pymath/power_of_three/README.md` at line 14, The mathematical expressions in
the README.md file use incorrect notation for exponents. Replace `33` with `3^3`
on line 14 to properly show three raised to the power of three. Replace `3x`
with `3^x` on lines 21 and 28 to use correct exponent notation throughout.
Additionally, remove the stray trailing backtick on line 21 that appears after
one of the expressions. These changes ensure consistent and correct mathematical
notation across all examples in the file.

BrianLusina and others added 2 commits June 22, 2026 09:39
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@BrianLusina BrianLusina merged commit 70bb453 into main Jun 22, 2026
6 of 8 checks passed
@BrianLusina BrianLusina deleted the feat/power-of-three branch June 22, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant