Skip to content

feat(math): add two negabinary numbers#198

Open
BrianLusina wants to merge 2 commits into
mainfrom
feat/math-add-two-negabinary-numbers
Open

feat(math): add two negabinary numbers#198
BrianLusina wants to merge 2 commits into
mainfrom
feat/math-add-two-negabinary-numbers

Conversation

@BrianLusina

@BrianLusina BrianLusina commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Describe your change:

Add two negabinary numbers

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

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for solving negabinary (base −2) number addition problems with alternative implementations.
  • Documentation

    • Expanded repository index with multiple new algorithm and data-structure problem categories including Dynamic Programming, graphs, hash tables, and matrices.
    • Added comprehensive documentation with examples for new problems.
  • Tests

    • Introduced parameterised unit tests for new functionality.

@BrianLusina BrianLusina self-assigned this Jun 16, 2026
@BrianLusina BrianLusina added Algorithm Algorithm Problem Array Array data structure Math labels Jun 16, 2026
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new pymath/adding_two_negabinary_numbers module with two implementations of negabinary (base -2) addition (add_negabinary and add_negabinary_2), a problem README, and parameterised unit tests. Updates DIRECTORY.md to add index entries across multiple categories and remove three misclassified entries.

Changes

Negabinary Addition Module

Layer / File(s) Summary
Negabinary addition implementations and README
pymath/adding_two_negabinary_numbers/__init__.py, pymath/adding_two_negabinary_numbers/README.md
Two public functions added: add_negabinary uses dual-index iteration with explicit carry rewrite rules, and add_negabinary_2 reverses inputs and normalises via modulo arithmetic. README documents the problem, three examples, constraints, and topic tags.
Parameterised unit tests
pymath/adding_two_negabinary_numbers/test_add_two_negabinary_numbers.py
AddTwoNegabinaryNumbersTestCase defines shared test data and two parameterised test methods, one for each implementation, asserting equality against expected outputs.

Directory Index Corrections and Additions

Layer / File(s) Summary
Directory index additions, removals, and reclassifications
DIRECTORY.md
Adds entries for Cherry Pickup, Number Of Connected Components, Custom Sort String, Game Of Life, Frequency Of The Most Frequent Element, Russian Doll Envelopes, Replace Words (Trie), Issubsequence, Acounts Merge, Sum Of All Subset Xor Totals, Nested Iterator, Sparse Vector, Adding Two Negabinary Numbers, and a Utils test link. Removes three misclassified entries (Puzzles/Arrays Maxlen Contiguous Binary Subarray, Pystrings Is Subsequence test link, Tests/Puzzles Replace Words test link).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

enhancement, Documentation

Poem

🐇 In base minus two, I carry and flip,
Each negabinary bit makes a trip.
Two approaches to sum what seems quite arcane,
With tests to confirm it's not all in vain.
The directory grows, all tidy and neat —
This rabbit's proud work is now complete! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description covers the main change and includes all critical checklist items completed, though it marks multiple unrelated checkboxes as completed. Clarify the description by only checking boxes that genuinely apply (only the first checkbox about adding an algorithm should be marked). Review whether doctests are actually present in the implementation.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature addition: implementing an algorithm to add two negabinary numbers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/math-add-two-negabinary-numbers

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: 1

🤖 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/adding_two_negabinary_numbers/README.md`:
- Around line 5-7: The README.md file in the
pymath/adding_two_negabinary_numbers directory has grammar and punctuation
issues in lines 5-7 that create ambiguity in the input format description. Fix
the redundant and awkwardly-phrased "format:  as an array" construct on line 5
by removing the colon and extra space, and correct the confusing "array, format"
phrase on line 7 by removing the comma. The sentences should flow more naturally
while clearly describing that the input numbers are provided as arrays of 0s and
1s from most significant to least significant bit.
🪄 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: 1bf1b73e-9af3-4035-93a7-cf085cf885e4

📥 Commits

Reviewing files that changed from the base of the PR and between 63bc9eb and e377c4c.

📒 Files selected for processing (4)
  • DIRECTORY.md
  • pymath/adding_two_negabinary_numbers/README.md
  • pymath/adding_two_negabinary_numbers/__init__.py
  • pymath/adding_two_negabinary_numbers/test_add_two_negabinary_numbers.py

Comment on lines +5 to +7
Each number is given in array format: as an array of 0s and 1s, from most significant bit to least significant bit.
For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3. A number arr in array, format is also
guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.

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 the input-format sentence to avoid ambiguity.

Line 5 through Line 7 have grammar/punctuation issues ("format: as an array" and "array, format") that make the input contract harder to parse.

Suggested patch
-Each number is given in array format:  as an array of 0s and 1s, from most significant bit to least significant bit. 
-For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3.  A number arr in array, format is also
-guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.
+Each number is given in array format as an array of 0s and 1s, from the most significant bit to the least significant bit.
+For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3.
+An array-format number is guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Each number is given in array format: as an array of 0s and 1s, from most significant bit to least significant bit.
For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3. A number arr in array, format is also
guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.
Each number is given in array format as an array of 0s and 1s, from the most significant bit to the least significant bit.
For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3.
An array-format number is guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.
🧰 Tools
🪛 LanguageTool

[grammar] ~5-~5: A determiner may be missing.
Context: ...0s and 1s, from most significant bit to least significant bit. For example, arr = [1...

(THE_SUPERLATIVE)

🤖 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/adding_two_negabinary_numbers/README.md` around lines 5 - 7, The
README.md file in the pymath/adding_two_negabinary_numbers directory has grammar
and punctuation issues in lines 5-7 that create ambiguity in the input format
description. Fix the redundant and awkwardly-phrased "format:  as an array"
construct on line 5 by removing the colon and extra space, and correct the
confusing "array, format" phrase on line 7 by removing the comma. The sentences
should flow more naturally while clearly describing that the input numbers are
provided as arrays of 0s and 1s from most significant to least significant bit.

Source: Linters/SAST tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Algorithm Algorithm Problem Array Array data structure Math

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant