ƒ(x)
- 327
- 0
Can someone please explain to me how to do combinations?
The discussion revolves around the concept of combinations in mathematics, specifically how to calculate them with and without replacement. Participants explore various methods for understanding combinations and permutations, including practical examples and programming approaches.
Participants express differing views on the accuracy of programming examples and the interpretation of combinations in specific scenarios. There is no consensus on the best method for calculating combinations, and multiple approaches are presented.
Some methods discussed may depend on specific assumptions about the items being combined, such as whether identical items are considered distinct. The programming examples may also rely on the specific language used and its handling of 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.