Knowledge Node - Combinatorics
(the intimidating way of saying "counting")

return to Knowledge Node index

Alright, enough of this mathematical theoretical garbage. Let's handle something that comes up in real life all the time! Let's say somebody named Pete-Kim-Kroggoa, the third, is having a wedding on the moon, and to promote interspecies diversity, has taken the effort to assign 8 unique species to every table. But, unfortunately, this is going on at a time of intergalactic war, and species A and species B are.. not getting along very well. How many ways can the host seat everyone so that species A and species B aren't sitting next to each other?

Now Pete-Kim-Kroggoa came to me, and asked me what I'd do. I thought to myself a bit, and then drew the following on a napkin.

In case you can't follow my cryptic scribbling, I figured, ok, there are 8 seats.  Let's put person A somewhere.  Ok, there are 8 seats so, we got 8.  Now that we've placed A somewhere, let's put B somewhere that's not close to A.  Since there are 5 seats that B can be placed that aren't close to A, we multiply 8 and 5 to get 40 total ways to place A and B without being next to each other.

Now, since there are still 6 species to sit in the remaining 6 seats, we simply permute them in every possible combination and arrangement.  Whenever you want to arrange different distinct objects, the number of arrangements is just the factorial of the number of objects.

For example, suppose you wanted to arrange A, B, and C in as many ways as possible.  3! (three factorial, or just shout 3 at the top of your lungs) = 1*2*3 = 6. ABC, ACB, BAC, BCA, CAB, CBA, are the six possible arrangements.

So, my final answer was 8 * 5 * 6! = 8 * 5 * (6*5*4*3*2*1) = 28,800 total valid arrangements.

Now, Pete-Kim-Kroggoa didn't trust me, and went to my Super-Frickin-Genius-Roommate, Matt the Destroyer of all that is Good in the World, and asked for his expert opinion.  After thinking it over a bit, he drew the following on a napkin.

Matt, the Destroyer of all that is Good in the World, decided that he would arrange A, C, D, E, F, G, and H, in as many places as possible, in a line, and each position in the line would correlate to a seat position.  After all that is done, he would look at his string of 7 letters and then insert B anywhere that he could that wouldn't be next to A.  Why, I found this ingenious. He clearly thinks very differently than I do.  To arrange 7 distinct objects in as many ways as possible, it's just 7! (seven factorial) = 5040.  And then, he figured, you can't insert B to the left of A, to the right of A, or at the very end (since seat 8 is next to 1), and there are therefore logically 5 positions where B can be inserted that are not next to A. So he took his answer of 5040 and multiplied it by 5, and got a whopping 25,200 total answers!

... wait a second.  How can two correct solutions produce different answers? Last time I checked, 28,800 does NOT equal 25,200.

I stared at these two problems, and for two days I labored over why this could be. I wrote computer programs that numerically solved for both, and came up with a fool-proof method to make sure that one answer was absolutely correct.  I was absolutely determined to find the solution, and after two full days of work, I have solved the discrepancy.  Before you read any further, do take the time and think about both problems, and try to come up with at least a guess as to why this could be true.

Well, I felt pretty dang proud of myself after finally coming up with why.  Quite frankly, I should have seen it right away, but I based it off the assumption that there are always 5 available seats when placing B.  Not so when doing Matt's method, as we are not dealing with seats but insertion points!!

Notice what happens when A isn't the first or the last letter in the string of positions.  Notice that the position to the left of the A and to the right are no longer valid, but this time it doesn't wrap around and kill a third insertion point, meaning, in this case there are 6 positions that B can be inserted into!

Species A is at the front and the end 2/7 of the time, and it's in the middle positions 5/7 of the time.  Therefore his answer should actually look like the following.

So hah! They really are the same number, believe it or not! That's why I absolutely love DisCo (Discrete and Combinatorial Mathematics). There are always many different ways to get the same solution, some are easier than others, and it all really just depends on how you think! DisCo saves interspecies relations once again! Hurrah for DisCo! Hurrah!

just curious... added 5/4/04

Some interesting references:

return to Knowledge Node index


return to the main page