Problem 1873. Break it up! Break it up!
You have N pennies. Write a Matlab script that will reveal how many different ways you can break up those pennies. For example, with 5 pennies, there are seven different ways you can divide them:
- (1,1,1,1,1)
- (2,1,1,1)
- (2,2,1)
- (3,2)
- (3,1,1)
- (4,1)
- (5)
The order of the coins does not matter, so (2,2,1) is considered the same combination as (2,1,2). You can assume that N will always be a positive integer.
Solution Stats
Problem Comments
-
4 Comments
Test case p(300)=9253082936723604 exceeds the maximum integer that can be represented exactly as a double precision number (namely, 2^53=9007199254740992); the fact that some solutions work for this case is just luck.
Changed to p(299), which is <2^53. Thanks for the heads up.
Interestingly, p(299) had some issues as well. Changed again to p(199), which seems to be working OK.
If I ever want to learn something, I dial up a problem from James.
Solution Comments
Show commentsProblem Recent Solvers54
Suggested Problems
-
Number of 1s in the Binary Representation of a Number
444 Solvers
-
The Hitchhiker's Guide to MATLAB
3297 Solvers
-
Numbers with prime factors 2, 3 and 5.
475 Solvers
-
Determine if input is a perfect number
238 Solvers
-
Generate binary combinations for a given number of bit(s)
92 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!