- #1
ƒ(x)
- 328
- 0
Can someone please explain to me how to do combinations?
Anonymous217 said:A method I've learned from a teacher maybe in like 6th grade is to draw out blanks like so:
__ __ __ __
The # of blanks is the amount of items/slots available. In each slot, you put the # of items/people that can be inside the slot. Always do specified slots first, and then do the rest. Multiply each blank and you have the permutation. Take the permutation and divide by the # of blanks and you get the combination.
For example, John has 3 types of socks, black, red, and white. How many different pairs of socks can he wear?
3 types; 2 slots (it's a pair)
3 2 1 = 6 permutations
6/3 = 2 combinations
Although elementary, this method is essentially using the combination and permutation formulas. I never got used to nCr and nPr types, especially if a problem combines more than one or two permutation/combinations. This is a fantastic way for doing it by hand that is just as fast (unless the # of slots get extremely large).
Mensanator said:If you want 'with replacement' use this:
>>> for i in n:
for j in n:
for k in n:
if i<=j and j<=k:
print(''.join([i,j,k]))
aaa
aab
aac
aad
aae
aaf
abb
abc
abd
abe
abf
acc
acd
ace
acf
add
ade
adf
aee
aef
aff
bbb
bbc
bbd
bbe
bbf
bcc
bcd
bce
bcf
bdd
bde
bdf
bee
bef
bff
ccc
ccd
cce
ccf
cdd
cde
cdf
cee
cef
cff
ddd
dde
ddf
dee
def
dff
eee
eef
eff
fff
Note that as combinations, each triplet is still in alphabetical order, but since replacent is allowed, you also get those triplets with repeated letters.
zgozvrm said:Uh, no...
You're program doesn't include several possibilities:
aba
aca
acb
ada
adb
adc
aea
aeb
aec
aed
afa
afb
afc
afd
afe
just to start...
You missed over half of them.
Woops. It does work. My example is just poorly worded. By 3 different types of socks, I meant only 1 of each (1 red sock, 1 white sock, and 1 black sock).zgozvrm said:This doesn't work.
If you're talking about how many different color combinations of socks John can wear, he has the following possibilities:
Black - Black
Black - Red
Black - White
Red - Red
Red - White
White - White
That's 6 combinations.
If you consider both socks of the same color to be the same sock, then for permutations, there would be only one Black-Black, one Red-Red, and one White-White. This would give:
Black - Black
Black - Red
Black - White
Red - Black
Red - Red
Red - White
White - Black
White - Red
White - White
or 9 permutations.
6 items; 3 slots.zgozvrm said:Choosing 3 of 6 items, you should get 20 combinations or 120 permutations.
zgozvrm said:Uh, no...
You're program doesn't include several possibilities:
aba
aca
acb
ada
adb
adc
aea
aeb
aec
aed
afa
afb
afc
afd
afe
just to start...
You missed over half of them.
zgozvrm said:I'm not familiar with the programming language you're using, but it looks like this would work:
for i in n:
for j in n:
for k in n:
print(''.join([i,j,k]))
Anonymous217 said:Woops. It does work. My example is just poorly worded. By 3 different types of socks, I meant only 1 of each (1 red sock, 1 white sock, and 1 black sock).
If the problem means he has 6 socks (2 of each color), then it goes like this:
6 5 = 30 perm
30/2 = 15 com
Mensanator said:Those are permutations, not combinations. There is ONLY one combination of 2 'a' and a 'b', and that is 'aab'.
zgozvrm said:Still, not a good example though. Most people would not differentiate one red sock from another, therefore there would only be 6 combinations of colors that could be worn. A clearer example would have John choosing any 2 of 6 differently colored socks. In that case, there would, in fact be 15 combinations.
Anonymous217 said:That's why I said the example is poorly worded. But that's irrelevant since the fact remains that the method works.
Combinations are a mathematical concept that involves selecting a set of items from a larger group without regard to order. They are important in many fields, including statistics, probability, and computer science.
To calculate combinations, you use the formula nCr = n! / (r!(n-r)!), where n is the total number of items and r is the number of items being selected. The exclamation mark represents the factorial function.
Yes, combinations can be used in many real-life situations. For example, they can be used to calculate the number of possible lottery combinations, the number of ways to select a team from a larger group of players, or the number of possible outcomes in a game of chance.
Combinations and permutations are similar concepts, but they differ in terms of order. Combinations do not consider order, while permutations do. For example, in a combination, selecting items A, B, and C is the same as selecting items C, B, and A. However, in a permutation, these two selections would be considered different because of the different order.
One helpful tip for solving combination problems is to break down the problem into smaller parts. For example, if you need to select 4 items from a group of 10, you can break it down into selecting 2 items from a group of 5 and then combining those selections. Additionally, understanding the context of the problem can help determine whether combinations or permutations should be used.