# Help with a complex Math problem

#### GoodSelf

##### Zhu Li! Do the thing!
So, I'm trying to figure out how many combinations I can make using the following restrictions, it's kind of hard to explain, but bear with me.

Let's say I have four actors in a party, each one of those actors has a small image associated with them, and when a battle starts, a large image is displayed showing all 4 of the small actor images. With this in mind, it doesn't matter if the order is 1234 or 3241, the image will stay the same, thus changing the number of combinations from 24 to 1 with 4 playable characters.

Now, let's say I have 20 playable actors - how many large images (not the small ones associated with each character) will I need to make sure one can be displayed for each possible party combination?

I guess a simpler way of explaining the math problem would be: I have 20 friends over my house, but only 4 chairs. In how many ways can all of my friends sit?

My brain is melting.

#### Wavelength

##### MSD Strong
The answer is 20!/4!: In other words, 20 times 19 times 18 times 17 times...times 3 times 2 times 1, divided by 24.

Since this number is way beyond the number of atoms in the world, you will definitely want to script the pictures to be shown individually rather than make a combination pic for each combination.

EDIT: I think Shaz is right. 20 * 19 * 18 * 17 / 24, since there are only 4 slots to fill. That still makes nearly 5000 combinations, so you'll still want to script the image display on a per-actor basis, I think.

Last edited:

#### Shaz

##### Global Moderators
If you're only allowing 4 of those 20 actors into your party at any given time, then you would have 20 x 19 x 18 x 17 possible combinations. However, each group of 4 would have all 24 order possibilities in there. So divide the result by 24.

#### EliteZeon

##### Third-Rate Noob
Ughh... Its been awhile since I last did a math problem like this. Alright, let's grab out google for formulas and a calculator.

This is going to require the combination formula I believe... lets see if I can paste this in:

Incase the formula didn't paste in:

Combination Formula = (n!)/[(k!)(n-k)!]

n= the total amount of party members
k= the the amount of party members in the combination.

I'll explain what n! and k! are in case you don't know. The ! represents the calculation of a factorial. A facotial represents a number being multiplied by all integers below it. Such as 4! = 4x3x2x1 = 24

This number is going to get big, so I'll do a quick example to explain why.

One party member equates to being able to choose 19 different buddies to pair up with.

For party member 1... you got like 19 combos, then 18 for party member 2 since you don't include party member 1, then 17 combos for party member 3 since you ignore pairing party member 1 and 2...

Or when calculating the first two people pairing together in the party it is:
19+18+17+16+15+14+13+12+11+10+9+8+7+6+5+4+3+2+1 = 190

In the above formula, we would put:

(20!)/[(2!)(20-2)!] = 190

Now getting into the main question...

Combination Formula = (n!)/[(k!)(n-k)!]

n= 20 party members
k= 4 people that can be tossed into the party

Amount of possible party combinations = (20!)/[(4!)(20-4)!]

Simplified: (20!)/[(4!)(16)!]

So two people out of 20 can be chosen in an order of 190 different ways... or rather, for the first two party members, the combo can be 95 different pairings if we don't consider the order they are paired in.

So n! (n factorial) is going to be 2.432902e+18 (that is a really big number)
K factorial is going to be 24. (n-k)! equates to 2.092279e+13.

So... we go and plug in chug.
(2.432902e+18) / [(24)(2.092279e+13)] = 4845 different party combinations.

This means out of 20 party members, they can be arranged in 4845 different ways. Since you just want one image to represent a potential 4 combos, we will divide this by 4.

So about 1211 or 1212 or so different images will be needed for each party composition.

My math might be a little off. But you're looking at A LOT of images.

I highly advise against this method of having a unique party image per 4 person combo. Unless you really can get that many images made.

EDIT
Hmm... I think I used the wrong formula. But... well you now know the party can be arranged 4845 different times!

EDIT 2
There is a reason I had to retake Calculus 2 a couple of times at my University. The answer is 4845... a whole number makes more sense, the formula already did the division required.

EDIT 3
Wow freaken ninjas man!

So looking over at everyone's else' answer.

With the combination formula, we have:

20! / [(4!)(16!)]

Mathematically, the 20! and 16! begins to cancel out each other, such that:

20! = 20x19x18x16x15x14x13x12x11x10x9x8x7x6x5x4x3x2x1
16! = 16x15x14x13x12x11x10x9x8x7x6x5x4x3x2x1

When 20!/16! occurs, the entire formula becomes. Every number of 16 and below gets knocked out and the formula simplifies to:

(20x19x18x17) / (4!)

and 4! = 24

Which brings us back to getting 4845 as the answer.

Last edited:

#### bgillisp

##### Global Moderators
@EliteZeon got it. This is a combination 20 choose 4 problem (since the order doesn't matter), making it 4845 total combinations.

### Latest Profile Posts

No water this time, just trying for a majestic cliffside... The cave snuck in because I liked it. Now I guess I need a mini cave map or "secret" for it.
Revamped the crew for my VN about thirty times. Only character that's stayed constant has been the fungus character. Guess it really grew on me...
I want to work on my reboot, but I don't have time to do it.
big image so i posted it as a spoiler
Just a reminder to back your projects up. Do it now!