Add integer partition algorithm using dynamic programming#976
Merged
siriak merged 5 commits intoTheAlgorithms:masterfrom Dec 25, 2025
Merged
Add integer partition algorithm using dynamic programming#976siriak merged 5 commits intoTheAlgorithms:masterfrom
siriak merged 5 commits intoTheAlgorithms:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #976 +/- ##
==========================================
+ Coverage 95.75% 95.77% +0.01%
==========================================
Files 350 351 +1
Lines 22892 22934 +42
==========================================
+ Hits 21920 21964 +44
+ Misses 972 970 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
@siriak, this is ready to be merged. Clippy error is a CI issue. No problem on other machines. |
siriak
approved these changes
Dec 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds an implementation of the integer partition algorithm using dynamic programming.
The partition function calculates the number of ways to express a positive integer as a sum of positive integers (order doesn't matter). For example, the number 5 can be partitioned in 7 ways:
Algorithm Overview
The implementation uses dynamic programming with a 2D memoization table where:
memo[n][k]represents the number of partitions ofninto at leastkpartsmemo[i][0] = 1(one way to partition into 0 parts)memo[n][k] = memo[n][k-1] + memo[n-k-1][k]This approach is based on the mathematical principle that:
Changes Made
src/dynamic_programming/integer_partition.rssrc/dynamic_programming/mod.rssrc/dynamic_programming/mod.rsTesting
All tests pass:
cargo test integer_partitionTest cases include:
partition(5)→ 7partition(7)→ 15partition(100)→ 190,569,292partition(1000)→ 24,061,467,864,032,622,473,692,149,727,991References
Checklist