Partitions of an integer

List all partitions of an integer
Updated 11 Mar 2018

View License

The money changing problem is a simple one to state. For example, how many different ways can one form change of a dollar (100 cents) by using only coins of denomination [1 5 10 25 50] ? (The answer is 292.)
Its an example of a general problem, i.e., in how many unique ways can an integer be partitioned as a sum of smaller positive integers?
I wrote partitions to solve the fully general problem, but it can be used with restrictions too. You can constrain the set of elements in the sum, and the maximum number of times any one elements can appear, as well as fixing the total number of terms that will appear in the final sum.
See the demo for a few examples of use.

Cite As

John D'Errico (2024). Partitions of an integer (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: partitiontable.m

Inspired: nsumk

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!


Version Published Release Notes

Comment change

Fix the plist=partitions(10,[1:5],[1],[4]) bug.

Added a new option: a user defined number of terms in the sum.