Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Finding all combination of portions of a number.

  1. Aug 7, 2012 #1
    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.
     
  2. jcsd
  3. Aug 7, 2012 #2
  4. Aug 7, 2012 #3
    This not-commented code is really hard to understand, could you explain the solution please?

    Thanks
     
  5. Aug 8, 2012 #4

    haruspex

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2016 Award

    Also search web for 'partition numbers'
     
  6. Aug 8, 2012 #5
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Finding all combination of portions of a number.
Loading...