SEARCH HOME
Math CentralQuandaries & Queries

search

Question from tony:

Hi - I have went through so many of your answers and can't find exactly what I need. I am looking to find all possible combinations of names programmatically.
Example:
If I have 5 names:
Mike
Tony
Joe
Bill
Bob

How many unique combinations can I put together (regardless of order)
For instance:
(Mike, Tony) is 1 combination
(Mike, Joe, Bob) is another combination
but (Tony, Mike) is the same as (Mike, Tony) so it would not be valid.

I am pretty good in logic and math but by no means an expert. I am a programmer and am looking to store each unique combination in a database (I will handle that part of course I just need help on the unique combinations)

Thank you very much !!

Tony,

There are 32 "combinations" (subsets) of a collection of 5 objects. One way to generate them uses binary representations. This is good for a programmer. Assign each of the 5 people a number that will correspond to a bit position. If you then count from 0 to 31 and look at the binary representation of each number, you get a different combination each time. The people included are those for whom the bit position corresponding to their number holds a 1. For example 25 = 11001 corresponds to persons 1, 2, and 5 (if bits are numbered from the left), and 0 = 00000 corresponds to the empty collection (no people).

The converse is also true, given any subset of the 5 people, the binary number formed by putting a 1 in the corresponding position when the person is in the subset and 0 otherwise lies between 0 and 31, inclusive.

Victoria

About Math Central
 

 


Math Central is supported by the University of Regina and The Pacific Institute for the Mathematical Sciences.
Quandaries & Queries page Home page University of Regina PIMS