Finding all combination of portions of a number.

  • Thread starter Thread starter lucasfeijo
  • Start date Start date
  • Tags Tags
    Combination
lucasfeijo
Messages
2
Reaction score
0
Is there a way to define in how many ways can I form a number by it's portions?

e.g: the number 5 has 6 ways:
1+1+1+1+1
2+1+1+1
2+3
2+2+1
3+1+1
4+1​

I was trying to program that and would appreciate any help!

Thanks.
 
Physics news on Phys.org
This not-commented code is really hard to understand, could you explain the solution please?

Thanks
 
Also search web for 'partition numbers'
 
The basic idea is, think of your number as 1+1+1+... and think of all the different ways to put brackets in this expression.
 
Back
Top