Hi guys,
Well, it's World Cup time and it seems only fitting that I submit something related to that. I was intrigued by the whole "Group of Death" concept. Intuitively (for me), a group of death should be a very unlikely event - yet they are always found in the World Cup. On talking to a mathematician, I was fascinated to find that they are supposedly unsurprising and quite predictable. Unconvinced, I decided to have a stab at simulating it. Here it is:
/*
* File: main.cpp
* Author: daniel
* Group of Death Simulation
*
* Created on June 15, 2010, 3:34 PM
*/
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(int argc, char** argv) {
// variable to record total groups of death for each run
int groupTotal = 0;
// holds total for number of death groups of overall simulation
int deathGroup = 0;
// random seed - how good is this I wonder?
srand(unsigned(time(NULL)));
// array to populate the vector
int box[32] = {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3};
// vector to store and randomize values
vector< int > group(box, box + 32);
// three nested loops - outermost is number of simulations, inner one is groups, inner most is teams
for(int i = 0; i < 10000; i++)
{
// randomize team rankings which are between 0 and 3
random_shuffle(group.begin(), group.end());
for(int j = 0; j < 8; j++) // number of groups
{
groupTotal = 0;
for(int k = 0; k < 4; k++) // number of teams
{
groupTotal += group.back();
group.pop_back();
}
if(groupTotal > 8) // threshold for group of death
{
deathGroup++;
}
}
group.assign(box, box + 32);
}
cout << "Number of groups of death: " << deathGroup << endl;
return (EXIT_SUCCESS);
}
Now, after a fair bit of mucking around (with simulations at 100, 10000 up to 100000000 times) I get a figure around 98 - 99%!?!? Is something going drastically wrong somewhere. Surely it can't be that likely. I should add that my definition of a group of death is a total greater than 8. Thanks in advance.
Daniel
PS: Maths was never my forte, so please be gentle!