Tiny maths question.

Started by
2 comments, last by Storyyeller 12 years, 11 months ago
Okay so user has 10 points that he / she is allowed to distribute between three factors: a, b and c. As such, the user may choose to put 10 in a but none in b or c (or any other combination). I need an efficient sum of some sort, that will differentiate all possible combinations, due to the sum resulting in different values.

Thanks in advance :)
Advertisement
Sorry, I'm not clear on what you actually want - you want to know how many possible combinations of point allocations there are?
[TheUnbeliever]
This sounds suspiciously like a school assignment... :)

Here's one way to look at it. Given the contraint that a+b+c=N, you only have two degrees of freedom. Once you choose a, you have N-a options for b. At that point, c has only one option: N-a-b. So:

a=N: b=0 c=0
a=N-1: b=0 c=1, b=1 c=0
a=N-2: b=0 c=2, b=1 c=1, b=2 c=0
a=N-3: b=0 c=3, b=1 c=2, b=2 c=1, b=3 c=0
...
a=0: b=0 c=N, b=1 c=N-1, b=2 c=N-2, b=3 c=N-3, ..., b=N c=0

If you visualize the pattern on an N×N square, the valid combinations form a triangle including the diagonal. That gives N×(N+1)/2 combinations. (If it excluded the diagonal, it would be N×(N-1)/2 instead.)


* . . . . . . . . .
* * . . . . . . . .
* * * . . . . . . .
* * * * . . . . . .
* * * * * . . . . .
* * * * * * . . . .
* * * * * * * . . .
* * * * * * * * . .
* * * * * * * * * .
* * * * * * * * * *

Okay so user has 10 points that he / she is allowed to distribute between three factors: a, b and c. As such, the user may choose to put 10 in a but none in b or c (or any other combination). I need an efficient sum of some sort, that will differentiate all possible combinations, due to the sum resulting in different values.

Thanks in advance :)


Why not just use 11a + b?
I trust exceptions about as far as I can throw them.

This topic is closed to new replies.

Advertisement