Skip to content

feat(maths): add repunit theorem helpers#14542

Closed
nickzerjeski wants to merge 4 commits intoTheAlgorithms:masterfrom
nickzerjeski:feat-repunit-theorem-13999
Closed

feat(maths): add repunit theorem helpers#14542
nickzerjeski wants to merge 4 commits intoTheAlgorithms:masterfrom
nickzerjeski:feat-repunit-theorem-13999

Conversation

@nickzerjeski
Copy link
Copy Markdown

Description

Add a small maths utility module for the repunit divisibility theorem.

Fixes #13999

Changes

  • Added maths/repunit_theorem.py with:
    • has_repunit_multiple(divisor)
    • least_repunit_length(divisor)
  • Added doctests and input validation.

Validation

  • python3 -m doctest -v maths/repunit_theorem.py

Copilot AI review requested due to automatic review settings April 13, 2026 08:44
@algorithms-keeper
Copy link
Copy Markdown

Closing this pull request as invalid

@nickzerjeski, this pull request is being closed as none of the checkboxes have been marked. It is important that you go through the checklist and mark the ones relevant to this pull request. Please read the Contributing guidelines.

If you're facing any problem on how to mark a checkbox, please read the following instructions:

  • Read a point one at a time and think if it is relevant to the pull request or not.
  • If it is, then mark it by putting a x between the square bracket like so: [x]

NOTE: Only [x] is supported so if you have put any other letter or symbol between the brackets, that will be marked as invalid. If that is the case then please open a new pull request with the appropriate changes.

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Apr 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a small number-theory helper module for repunit divisibility (existence and minimal length of a repunit multiple for a given divisor), with doctest examples and basic validation.

Changes:

  • Added maths/repunit_theorem.py with has_repunit_multiple() and least_repunit_length() implemented via modular arithmetic.
  • Added a new knapsack_space_optimized() implementation to dynamic_programming/knapsack.py (unrelated to the stated repunit feature).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
maths/repunit_theorem.py New utilities for repunit divisibility and least repunit length computation.
dynamic_programming/knapsack.py Adds a space-optimized 0/1 knapsack helper with input validation and doctests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +27 to +29
if divisor <= 0:
raise ValueError("divisor must be a positive integer")
return gcd(divisor, 10) == 1
Comment on lines +42 to +45
def knapsack_space_optimized(
capacity: int, weights: list[int], values: list[int], num_items: int
) -> int:
"""
Comment on lines +78 to +83
if num_items < 0:
raise ValueError("The number of items cannot be negative.")
if capacity < 0:
raise ValueError("The knapsack capacity cannot be negative.")
if num_items > len(weights) or num_items > len(values):
raise ValueError("The number of items exceeds the provided input lengths.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed invalid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: The Repunit theorem

2 participants