// Arup Guha
// 9/6/2023
// Solution to CIS 3362 Quiz #1 Question 6

#include <stdio.h>

double probsame(int numcandy[]);

int main() {

    // Test with input from a different quiz =) Answer is fraction 66/5049
    int vals[100];
    for (int i=0; i<100; i++) vals[i] = i+1;
    printf("%lf\n", probsame(vals));
    return 0;
}

// Returns the index of coincidence of the frequency data stored in numcandy (assumed to be size 100).
double probsame(int numcandy[]) {

    int n = 0;
    int num = 0;

    // Go through each element.
    for (int i=0; i<100; i++) {

        // We need to know total candy.
        n += numcandy[i];

        // This is the numerator.
        num += (numcandy[i]*(numcandy[i]-1));
    }

    // Take the numerator and divide by the denominator in the formula.
    return 1.0*num/n/(n-1);
}
