//Brian & Keith
//9/9/11
//cards.c

#include <stdio.h>;
#include <time.h>;

const int NUMTESTS = 10000;

int main()
{

    srand(time(0));

    double totCards = 0;
    int x;

    // Run each trial.
    for(x = 0; x < NUMTESTS; x++)
        totCards += run();

    // Calculate the average and print.
    double ave = totCards / NUMTESTS;
    printf("Average number of cards to get all 792: %.03lf", ave);

    return 0;
}

// Runs one trial.
int run()
{
    int cards[792];

    // We haven't gotten any cards yet.
    int x;
    for(x = 0; x < 792; x++)
        cards[x] = 0;

    int found = 0;
    int tries = 0;

    // Keep on getting cards until you have each different one.
    while(found < 792)
    {
        int temp = (rand() * 32768 + rand()) % 792;

        // Process a distinct card.
        if(cards[temp] == 0)
        {
            found++;
            cards[temp] = 1;
        }

        // Count all cards.
        tries++;
    }

    // Number of cards tried.
    return tries;
}
