Jump to content
  • Advertisement
Sign in to follow this  
ReubenESTD

Tiny maths question.

This topic is 2595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
Advertisement
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.)


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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!