feat(maths): add repunit theorem helpers#14542
feat(maths): add repunit theorem helpers#14542nickzerjeski wants to merge 4 commits intoTheAlgorithms:masterfrom
Conversation
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:
NOTE: Only |
There was a problem hiding this comment.
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.pywithhas_repunit_multiple()andleast_repunit_length()implemented via modular arithmetic. - Added a new
knapsack_space_optimized()implementation todynamic_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.
| if divisor <= 0: | ||
| raise ValueError("divisor must be a positive integer") | ||
| return gcd(divisor, 10) == 1 |
| def knapsack_space_optimized( | ||
| capacity: int, weights: list[int], values: list[int], num_items: int | ||
| ) -> int: | ||
| """ |
| 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.") |
Description
Add a small maths utility module for the repunit divisibility theorem.
Fixes #13999
Changes
maths/repunit_theorem.pywith:has_repunit_multiple(divisor)least_repunit_length(divisor)Validation
python3 -m doctest -v maths/repunit_theorem.py