Calculating "combinations".

  • Thread starter Thread starter John Fitzsimons
  • Start date Start date
J

John Fitzsimons

Hi everyone,

One has a list of 12 items. How many "unique" combinations would that
make ? Is it 12 to the power of 12 ? If not then what would it be and
what software could provide the answer please ?

Regards, John.
 
John said:
Hi everyone,

One has a list of 12 items. How many "unique" combinations would that
make ? Is it 12 to the power of 12 ? If not then what would it be and
what software could provide the answer please ?

Regards, John.

I'm really reaching back here, but I believe that if order does NOT
matter, it's 1+2+3+...+12. If order DOES matter, it's 12! -- i.e.
1x2x3x...x12.
 
John ....

The following is an excerpt from the anagrams_Read_This.txt file
that I put together a few months back and the basic algorithms
for combinations and permutations were used in the anagrams.py
program ....

The following link contains a small python script
to compute the number of combinations and permutations
for a given size set ....

http://fastq.com/~sckitching/Python/factorial.py
[ 2.6 KB ]

The following line produces the output shown
mixed in the notes below ....

python factorial.py 9

Notice that almost a million permutations are possible
for a set of 9 elements, e.g. , the length of the word
extrovert ....


Background .... A bit of math ....

1. Subset Generation ....

An N element set has ( 2 ** N ) subset combinations ....

For the example word extrovert which is 9 characters long
there are 512 subset combinations with each subset containing
words of different length ....

combin( 9 , 0 ) .... 1
combin( 9 , 1 ) .... 9
combin( 9 , 2 ) .... 36
combin( 9 , 3 ) .... 84
combin( 9 , 4 ) .... 126
combin( 9 , 5 ) .... 126
combin( 9 , 6 ) .... 84
combin( 9 , 7 ) .... 36
combin( 9 , 8 ) .... 9
combin( 9 , 9 ) .... 1

Total Combinations 512


2. Anagram Permutations ....

The number of permutations
of n things taken t at a time
is given by the factorial expression ....

nt = ( n! / ( n - t )! )

permut( 9 , 0 ) .... 1
permut( 9 , 1 ) .... 9
permut( 9 , 2 ) .... 72
permut( 9 , 3 ) .... 504
permut( 9 , 4 ) .... 3024
permut( 9 , 5 ) .... 15120
permut( 9 , 6 ) .... 60480
permut( 9 , 7 ) .... 181440
permut( 9 , 8 ) .... 362880
permut( 9 , 9 ) .... 362880

Total Permutations 986410

--- Note By : Alex Martelli ---

The difference in Combinations and Permutations
being that ordering of items does not distinguish Combinations,
while it is ALL that distinguishes Permutations ....
 
I'm really reaching back here, but I believe that if order does
NOT matter, it's 1+2+3+...+12. If order DOES matter, it's 12! --
i.e. 1x2x3x...x12.

If order matters, there are 12! permutations of the 12 items. If order
does not matter, there is only one way to list the 12 items.
 
| One has a list of 12 items. How many "unique" combinations
| would that make ?
|
| Is it 12 to the power of 12 ?
|
| If not then what would it be and what software could provide
| the answer please ?

John ....

Running the factorial.py program mentioned
in my previous post for a set of size 12 ....

python factorial.py 12

factorial.py

factorial( 12 ) ...... 479001600

combin( 12 , 0 ) .... 1
combin( 12 , 1 ) .... 12
combin( 12 , 2 ) .... 66
combin( 12 , 3 ) .... 220
combin( 12 , 4 ) .... 495
combin( 12 , 5 ) .... 792
combin( 12 , 6 ) .... 924
combin( 12 , 7 ) .... 792
combin( 12 , 8 ) .... 495
combin( 12 , 9 ) .... 220
combin( 12 , 10 ) .... 66
combin( 12 , 11 ) .... 12
combin( 12 , 12 ) .... 1

Total Combinations 4096


permut( 12 , 0 ) .... 1
permut( 12 , 1 ) .... 12
permut( 12 , 2 ) .... 132
permut( 12 , 3 ) .... 1320
permut( 12 , 4 ) .... 11880
permut( 12 , 5 ) .... 95040
permut( 12 , 6 ) .... 665280
permut( 12 , 7 ) .... 3991680
permut( 12 , 8 ) .... 19958400
permut( 12 , 9 ) .... 79833600
permut( 12 , 10 ) .... 239500800
permut( 12 , 11 ) .... 479001600
permut( 12 , 12 ) .... 479001600

Total Permutations 1302061345

If order doesn't matter,
then the number of combinations, 4096 ,
is the answer ....

If order does matter,
then the number of permutations, 1,302,061,345 ,
is the answer ....
 
One has a list of 12 items. How many "unique" combinations would that
make ? Is it 12 to the power of 12 ? If not then what would it be and
what software could provide the answer please ?

12*11*10*9*8*7*6*5*4*3*2*1 = 479001600

In this case, order has nothing to do with it, since you are using all 12
items.
 
Hi,
Here's a QuickBASIC function to calculate combinations. With a
little modification, this can be converted to run in VBScript as well.

DECLARE FUNCTION Combinations# (n&, r&)
n& = 49
r& = 6
PRINT "Combinations of"; n&; "objects taken";
PRINT r&; "at a time = "; Combinations#(n&, r&)

' ************************************************
' ** Name: Combinations# **
' ** Type: Function **
' ** Module: PROBSTAT.BAS **
' ** Language: Microsoft QuickBASIC 4.00 **
' ************************************************
'
' Returns the number of combinations of n& items
' taken r& at a time.
'
' EXAMPLE OF USE: c# = Combinations#(n&, r&)
' PARAMETERS: n& Number of items
' r& Taken r& at a time
' VARIABLES: result# Working result variable
' j& Working copy of r&
' k& Difference between n& and r&
' h& Values from r& through n&
' i& Values from 1 through j&
' MODULE LEVEL
' DECLARATIONS: DECLARE FUNCTION Combinations# (n&, r&)
'
FUNCTION Combinations# (n&, r&) STATIC
result# = 1
j& = r&
k& = n& - r&
h& = n&
IF j& > k& THEN
SWAP j&, k&
END IF
FOR i& = 1 TO j&
result# = (result# * h&) / i&
h& = h& - 1
NEXT i&
Combinations# = result#
END FUNCTION

If you are looking for Permutations, I have code for that as well.
Hope This Helps.

Joe
 
John said:
Hi everyone,

One has a list of 12 items. How many "unique" combinations would that
make ? Is it 12 to the power of 12 ? If not then what would it be and
what software could provide the answer please ?

John, are you after software, or somebody to answer your question for
you? :)
Here's the latter anyway:
Your question is a bit ambiguous because you didn't specify your "rules"
for filling the 12 empty slots with the 12 items, nor the "implied
uniqueness" of the items. Let's say you have the letters A-L.
If you can use any of those in any of the slots, then your solution is
correct. This is the process of "selection WITH replacement".
If you can't repeat a letter, then the answer is factorial 12 or 12!
This is "selection WITHOUT replacement" and this attracted the factorial
answers you got. Windows Calculator lets you evaluate factorials.
If the 12 items are not judged to be unique e.g. 3 red, 4 blue, 5 green
balls, then the situation gets more complex, and it's mathematics more
than software that is needed to calculate the answer. In this case, it's
12! / (3! x 4! x 5!)

HTH
 
John, are you after software, or somebody to answer your question for
you? :)

I was after confirmation that my statement for calculation was correct
and after a program (calculator ?) that would give the result. A step
by step might have been an added bonus.

For example, I haven't used a "scientific" calculator so if 12 to the
power of 12 was the answer I wouldn't know how to arrive at the answer
using a calculator.
Here's the latter anyway:
Your question is a bit ambiguous because you didn't specify your "rules"
for filling the 12 empty slots with the 12 items,

Well, any combination of 12 items is surely pretty clear. Isn't it ?
nor the "implied
uniqueness" of the items.

Well, I would think item 1 and 3 would be the same as 3 and 1. So
"uniqueness" would mean that either (not both) would be an answer.

Though I now see that the word "unique" complicates matters. For
example, suppose all "combinations" of 1 and 2 is 2 squared then the
answer should be 4.

Maybe ? :

1 or
2 or
1 and 2 or
2 and 1.

Four options.

"Uniqueness gives me 3 as the third and fourth options are effectively
the same.
Let's say you have the letters A-L.
If you can use any of those in any of the slots, then your solution is
correct.

12 to the power of 12 ?
This is the process of "selection WITH replacement".
If you can't repeat a letter, then the answer is factorial 12 or 12!

Sorry, I don't know what the difference between 12 to the power of 12
and factorial 12 is. Come to think of it I am now not sure I even
understand the former ! :-(
This is "selection WITHOUT replacement" and this attracted the factorial
answers you got. Windows Calculator lets you evaluate factorials.
If the 12 items are not judged to be unique e.g. 3 red, 4 blue, 5 green
balls, then the situation gets more complex, and it's mathematics more
than software that is needed to calculate the answer. In this case, it's
12! / (3! x 4! x 5!)

Umm. Give me a year, or two, to digest it.

Regards, John.
 
| One has a list of 12 items. How many "unique" combinations
| would that make ?

If order doesn't matter,
then the number of combinations, 4096 ,
is the answer ....
If order does matter,
then the number of permutations, 1,302,061,345 ,
is the answer ....

Thanks. I first need to properly understand the difference between
combinations and permutations. Then I will know which is the "correct"
answer. :-)

For example I wouldn't know whether

1 and 3 were a combination, or a permutation. The same would go for 1
and 4 and 7 etc.


Regards, John.
 
Hi everyone,

One has a list of 12 items. How many "unique" combinations would that
make ? Is it 12 to the power of 12 ? If not then what would it be and
what software could provide the answer please ?

Find a calculator that does combinations (nCR) and permutations (nPR).
Should be a ton of them out there.

Bob
 
John said:
I was after confirmation that my statement for calculation was correct
and after a program (calculator ?) that would give the result. A step
by step might have been an added bonus.

For example, I haven't used a "scientific" calculator so if 12 to the
power of 12 was the answer I wouldn't know how to arrive at the answer
using a calculator.


Well, any combination of 12 items is surely pretty clear. Isn't it ?

Not really, as exemplified below. One of the biggest problems with
probability is expressing the problem/ situation in an unambiguous way.
Had you expressed an exam question as "One has a list of 12 items. How
many "unique" combinations would that make ?" then you would end up with
quite a number of interpretations and answers. Perhaps an interesting
"how many" puzzle within itself. :)
Well, I would think item 1 and 3 would be the same as 3 and 1. So
"uniqueness" would mean that either (not both) would be an answer.

OK, now the ambiguity is starting to sort itself out. You seem to be
asking about selections (without regard to ordering of the selected
items) rather than arrangements. That's incidentally exactly the way the
term "combination" is used for in mathematical parlance, as opposed to
"permutation". (1,3) would be regarded as different permutation to (3,1)
but both represent the same combination.
Though I now see that the word "unique" complicates matters. For
example, suppose all "combinations" of 1 and 2 is 2 squared then the
answer should be 4.

Maybe ? :

1 or
2 or
1 and 2 or
2 and 1.

Four options.

"Uniqueness gives me 3 as the third and fourth options are effectively
the same.

That's exactly the distinction between selections/combinations (=3) and
arrangements/permutations (=4) I mentioned above. I always used the
analogy of thinking about whether you're going to be placing the
selected items into numbered / distinguishable slots, or just tossing
them into a hat... if that helps. In your case it's the hat I think.

But the "uniqueness" factor is usually more specific to what's being
sought. For instance, if there are 9 boys and 11 girls in a class, how
many different arrangements in a line are possible? The answer will
depend on whether each is treated as an individual (unique by name say)
or whether the only distinction being made is boy or girl (not all
unique). Depends on what you're looking for. In your case, I think you
*are* regarding each of the items as unique (distinguishable).
12 to the power of 12 ?

True if you're using all 12 letters, you're allowing letters to be
repeated and you're looking at the number of *arrangements* within the
group of 12, which I don't think you are from your example above.
Sorry, I don't know what the difference between 12 to the power of 12
and factorial 12 is. Come to think of it I am now not sure I even
understand the former ! :-(

12 to the power 2 is 12 x 12 (2 terms)
12 to the power 3 is 12 x 12 x 12 (3 terms)
12 to the power 4 is 12 x 12 x 12 x 12 (4 terms)
So 12 to the power 12 is 12 x 12 x 12 ... x 12 (twelve terms)

12! = 12 x 11 x 10 x 9 ... x 3 x 2 x 1
also 12 terms, but with the number of available choices reducing by one
for each term. This corresponds to the "without replacement" or "no
repeats allowed" situation - once you've used an item it's removed from
the pool of possible choices.

All that said, from the example you gave above, using the digits 1 and
2, I'm now guessing that you are actually after the total number of all
possible *selections* of *up to* 12 items from the 12 items you have.
That is, all possible groups of size 1, 2, 3, ... 12 from a pool of 12
*unique* items. For your simple example, the answer you want is 3 -
being the selections (1), (2), (1,2) with (1,2) and (2,1) being regarded
as the same thing. Also, you're not allowing repetition of something
already selected. In summary:

- 12 unique items
- all group sizes from 1 to 12 inclusive
- selection without replacement (no repeats)
- no regard to order (looking at selections rather than arrangements)

Is this right? If so, then it's actually not a trivial problem. You're
wanting to count all the selections of size 1, size 2, size 3... up to
size 12 and add the counts together. Without getting into proofs etc.,
the number of possibilities for any one of these groups (of size r) is
given by
12! / { (12-r)! x r!} or 12(C)r for short.
It's less scarey than it looks - the number of possibilities for a group
of 3 would be 12(C)3 or 12! / (9! x 3!). The good part about these
factorial expressions is that lots of stuff cancels out, so this becomes
just
(12 x 11 x 10) / (3 x 2 x 1) = 220

All you have to do then is to repeat for r = 1 to 12 and add them all
up. Easy ;-)
Actually it *is* easy because the number you're after is:
12(C)1 + 12(C)2 + 12(C)3 + ... + 12(C)10 + 12(C)11 + 12(C)12

There's a handy formula called the binomial theorem that can be applied
to this exact kind of expression, and it turns out that the answer is 2
to the power 12 minus one or 2^12 - 1. More generally, if there were n
items, the answer would be 2^n - 1. To run this through Windows
Calculator is just a matter of keying:
2
x^y button
12
- button
1
= button
Answer: 4095

Just as easy is 12! if you want it:
12
n! button
Answer: 479001600

Just for interest, the "minus one" is there to exclude the single (only)
group of size zero.

OK, since this has become a novel now anyway, and since you obviously
want explanation rather than just an answer, here's a bit of lodown on
how all this complex-looking math really just boils down to counting
things. I'll use the example of the 12 unique letters A-L. You're
interested in groups of all sizes, and counting selections/ combinations
rather than ordered permutations. It turns out that it's easiest to
count the more numerous *arrangements* first, then reduce the count so
that different arrangements of the same letters all count as one.

Consider all the groups of size 3 that are possible, by having 3
distinguishable slots to fill. The first slot can have any of 12 items,
the second any of the 11 remaining items and the third any of 10
remaining. The total number of possibilities is then 12 x 11 x 10
(=1320).

So the number of "permutations" or arrangements of 3 letters, selected
without replacement from a group of 12 unique letters is
12 x 11 x 10
In factorial terms this is 12! / (12 - 3)!

Now let's pick on a particular trio of letters, say J, A, F. How many
times do they appear within the 1320 possibilities? In other words, how
many arrangements can we make out of 3 distinct letters? Again, think of
filling 3 distinguishable slots with 3 different items. First slot - 3
choices, second 2, third 1. So there are 3 x 2 x 1 (=3!) possible
arrangements of J,A,F -
JAF, JFA, AJF, AFJ, FJA, FAJ
So the 1320 arrangements could be placed in groups of 6 like the above,
and each group of 6 would represent the same set of letters (as chucked
into a hat, as it were).

So the number of "combinations" or selections of 3 letters, selected
without replacement from a group of 12 unique letters is
12 x 11 x 10 / (3 x 2 x 1)
In factorial terms this is 12! / { (12 - 3)! x 3! }

This analysis can be repeated for groups of all sizes from 1 to 12, and
the results added to give the total number of possibilities. The
factorial expressions are used because they're a standard mathematical
function (convenience) supported on calculators, spreadsheets etc. But
the crux of the whole thing boils down to just counting and
multiplication... not scarey at all! ;-)

Finally an aside. The problem with ambiguity in the wording of such
problems is so well recognised that it's led to many "trick" puzzles and
paradoxes. One classic, relating directly to the example you gave is
this:

Family A has 2 children. The oldest is a boy. What's the probability
that both are boys? Family B has 2 children. One of them is a boy.
What's the probability that both are boys?

Interesting problem yours, ambiguities & all :)... cleared a few cobwebs
off those 5¼" neural storage units that hadn't been accessed for quite a
while.
 
| Thanks. I first need to properly understand the difference
| between combinations and permutations.
| ...

John ...

In combinations order is not important ....

12 is the same as 21 ... combinations of 2 numbers

123 is the same as 321 ... combinations of 3 numbers
dog is the same as god ... combinations of 3 letters

The permutations are the anagrams,
e.g. , shuffling the same selected combined letters around
to produce a different word ...

12 is NOT the same as 21 ...
123 is NOT the same as 321 ...
dog is NOT the same as god ...
 
<
[re using the binomial theorem to add the first 12 binomial
coefficients]
Just for interest, the "minus one" is there to exclude the single
(only) group of size zero.

I object! The empty list is in fact a list, and should be counted!

Joking aside, that was a very good, thorough write-up. Though I
thought about it, I decided not to attempt it, mostly because ASCII is
so limiting when it comes to mathematical explanations. (At the very
least, I'd want sigma notation.)
 
»Q« said:
<
[re using the binomial theorem to add the first 12 binomial
coefficients]
Just for interest, the "minus one" is there to exclude the single
(only) group of size zero.

I object! The empty list is in fact a list, and should be counted!

You like 12(C)0? No probs - even simpler: 2^12 :-)
Joking aside, that was a very good, thorough write-up. Though I
thought about it, I decided not to attempt it, mostly because ASCII is
so limiting when it comes to mathematical explanations. (At the very
least, I'd want sigma notation.)

One of my pet desires/ wish list items. Some characters that are
actually of some *use* in the top end of the standard font table. I've
tried all sorts of tricks with ASCII to emulate symbols/ math. Never
found anything really satisfactory though. I used some homemade
abbreviations like SUM(i=1->n){expression} and
ANT{function} for sigma and antiderivative, but it still ends up looking
like a mess. Such is ASCII :-(
 
»Q« said:
<Joking aside, that was a very good, thorough write-up. Though I
thought about it, I decided not to attempt it, mostly because ASCII is
so limiting when it comes to mathematical explanations. (At the very
least, I'd want sigma notation.)

OK, now you've fired me Q! I my efforts to simplify all this, I started
thinking about another situation and got myself knotted. Maybe you can
help. Let's say it's 12 *non*unique items - 3 red, 4 blue, 5 green. Same
problem - how many *unique* *combinations* (not arrangements) are there
for selections of all sizes? I can't see a simple way of fathoming it.
 
John Fitzsimons wrote:
True if you're using all 12 letters, you're allowing letters to be
repeated and you're looking at the number of *arrangements* within the
group of 12,
Okay.

which I don't think you are from your example above.

Yep.

All that said, from the example you gave above, using the digits 1 and
2, I'm now guessing that you are actually after the total number of all
possible *selections* of *up to* 12 items from the 12 items you have.
Yes.

That is, all possible groups of size 1, 2, 3, ... 12 from a pool of 12
*unique* items. For your simple example, the answer you want is 3 -
being the selections (1), (2), (1,2) with (1,2) and (2,1) being regarded
as the same thing. Also, you're not allowing repetition of something
already selected. In summary:
Yes.

- 12 unique items
- all group sizes from 1 to 12 inclusive
- selection without replacement (no repeats)
- no regard to order (looking at selections rather than arrangements)
Is this right?

Yes.

There's a handy formula called the binomial theorem that can be applied
to this exact kind of expression,

Answer: 479001600

So all fitwell had 12 Agent shortcuts all he needed to do was have
479,001,600 batch files and he should have "everything covered"
eh ? :-)

< snip >

Thanks. I actually understood some of that ! Thanks also for the step
by step and key info.

Regards, John.
 
| Thanks. I first need to properly understand the difference
| between combinations and permutations.
In combinations order is not important ....
12 is the same as 21 ... combinations of 2 numbers
123 is the same as 321 ... combinations of 3 numbers
dog is the same as god ... combinations of 3 letters
The permutations are the anagrams,
e.g. , shuffling the same selected combined letters around
to produce a different word ...
12 is NOT the same as 21 ...
123 is NOT the same as 321 ...
dog is NOT the same as god ...

Ah ! Much clearer now. Why didn't you say that before ? < he he >

Many thanks for your input/explanation. :-)

Regards, John.
 
One of my pet desires/ wish list items. Some characters that are
actually of some *use* in the top end of the standard font table.
I've tried all sorts of tricks with ASCII to emulate symbols/
math. Never found anything really satisfactory though. I used some
homemade abbreviations like SUM(i=1->n){expression} and
ANT{function} for sigma and antiderivative, but it still ends up
looking like a mess. Such is ASCII :-(

So get to work on a TeX version. ;)

In case anyone is wondering wtf kind of notations we are talking
about, Wikipedia has a pretty good entry for the binomial theorem.
<http://www.wikipedia.org/wiki/binomial_theorem>.

The special case of adding up the coefficents Alan made use of has

x = y = 1 and n = 12
 
OK, now you've fired me Q! I my efforts to simplify all this, I
started thinking about another situation and got myself knotted.
Maybe you can help. Let's say it's 12 *non*unique items - 3 red, 4
blue, 5 green. Same problem - how many *unique* *combinations*
(not arrangements) are there for selections of all sizes? I can't
see a simple way of fathoming it.

I don't see a way other than taking it by cases, then adding. I'll
mull it over some more when I get some time.
 
Back
Top