How to generate Integer Partitions?

  • Given an integer n, it is possible to represent it as the sum of one or more positive integers.This representations called a partition if the order of the x; is of no consequence. Thus two partitions of an integer n are distinct if they differ with respect to the x; they contain.

    For example, there are seven distinct partitions of the integer 5:

    5=5

    5=4+1

    5=3+2

    5=3+1+1

    5=2+2+1

    5=2+1+1+1

    5=1+1+1+1+1

    The total is 7

  • And your objective is? Generating the list? Or just determining the number of partitions, given N ? Also, have you made any attempt at whatever it is you want to accomplish, and if so, what code or T-SQL did you write?

    Steve

    (aka smunson)

    :):):)

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • This doesn't look particularly easy... Take a look at the following links:

    http://en.wikipedia.org/wiki/Partition_of_an_integer#Partition_function

    http://www.research.att.com/~njas/sequences/A000041

    I'm pretty good with numbers, but the math in Rademacher's series is more than a bit too complex for me. I was hoping for a scalar solution, at least for the number of partitions, but that appears impractical. However, generating the partitions themselves might be approachable using a recursive CTE, but it won't be easy. You are likely going to want to have a "Tally table" of numbers. Look that up on this forum. Somehow, this looks like one of those cases where a WHILE loop is going to be essential. Anyone feel like proving me wrong? I'd love to see the result...

    Steve

    (aka smunson)

    :):):)

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply