# It has been too long since I've taken math. How do I calculate this?

OK. Background.

I’m trying to make a computer RPG. I wish to allow party switching. I figured out a way to do it, but I’m not sure if it’d be worth the effort. To figure this out I decided to calculate the number of possible parties. After doing it, I realised - I’d forgotten how to do that. The only way I could remember [n*(n-1)*(n-2)] gave a total that counted ABC and CBA (etc) as separate groups.

But, for my purposes, they’re identical.

Could somebody remind me of the formula to calculate that, which I’ve forgotten in the 7 years since I last took math?

n!
C(n,m) = -----------
m! (n - m)!

I don’t quite understand the background, but I think you’re asking “How many ways can I choose a group of 3 out of 10 (order doesn’t matter.)” Check out http://mathworld.wolfram.com/BinomialCoefficient.html which describes exactly this. Hopefully whatever you’re programming in will include a binomial function, if you need it.

I’m afraid that’s not helping me any.

Talk to me like I’m an idiot - or at least doing this for the first time. It’s all gone.

My problem is thus:

I have 22 items (characters, in this case). At a given time you can choose 3.

I want to know how many unique groupings of those items I can make, assuming ABC and CBA are identical for all current intents and purposes.

nCm = n! / m!(n-m)!

n! = 1x2x3x…xn

n in your case is 22
m is 3

A scientific calculator should have an nCr button on it to make sure your results are right.

You will have 22x21x20/(1x2x3) = 1540 different combinations.

Im getting 1540 possible combinations using a method I deduced myself. Can anyone confirm or deny?

What I’m doing isn’t efficient, but it works.

Let’s call each attribute one through twenty two.

1-2-x has 20 combinations
1-3-x has 19 combinations (as 2 has been used up)
1-4-x has 18

etc.

2-3-x has 19 combinations
2-4-x has 18 combinations
2-5-x has 17

3-4-x has 18 combos…
and so on and so forth.

Add 'em all up, and you get 1540. I can work out a formula (which probably is what’s linked to), but this is faster for me for the moment.

The number of combinations is given by 22! / ( 3! * ( 22 - 3 )! ). ! is an operator called the factorial. I can’t think of how to word it, so I’ll show you:
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
n! = n * (n-1) * (n-2) * … * 1

The formula is this:
The number of combinations (where order is irrelevant) of r elements selected from a set of n units is given thus: [sub]n[/sub]C[sub]r[/sub] = n! ÷ ( r! * ( n - r )! )

The number of permutations (where order is relevant) of r elements selected from a set of n units is given thus: [sub]n[/sub]P[sub]r[/sub] = n! ÷ ( n - r )!

Well, seems that Sergio beat me to the formula. But it was right. Cool.

+MDI has the right formula; Sérgio and pulykamell have the right answer.

Thank you all. That helped. I was even able to calculate a complication I forgot about earlier (the AB_ and A__ cases).

I not only have the right answer, but the right formula. When deducing the formula for the number of combinations of n objects m-wise you have

C = n*(n-1)(n-m+1)/(12…*m)

Now, if you multiply the numerator and the denominator by (n-m)! = 12(n-m), you get in the numerator n(n-1)(n-m+1)(n-m)…*1 = n!

So the final formula is n!/[(n-m)!*m!] , easier to remember, but involving much more calculations.

As they say, there’s more than one way to skin a cat. As long as you arrive at the right answer through mathematically sound means.

I missed it down there. Sorry. No slight intended.

And you are of course correct. I intended no slight on your method. It’s not something I would’ve deduced, as I am not particularly mathematically-inclined. I just wanted to provide him a way to have a computer or calculator figure it out.

Oh, no offense taken. It’s just that I too always forget these simple statistics formulas, so I write down a small group of numbers (in my case, I started with five) and wrote down the three-number combos possible from this. I noticed it went (3+2+1) + (2+1) + (1). So then I extrapolated.

Like I said, not the best method by any stretch, but reasonable if you’ve completely blanked on how to do it.