#include "lang.h"
#include "grader.h"
// The 'brain' of our program:
// 56 languages, 65536 possible character codes
// Using 'static' so the data stays in memory between the 10,000 calls
static int freq[56][65536];
void excerpt(int E[]) {
int best_lang = 0;
double max_score = -1.0;
// 1. SCORING PHASE: Compare the current excerpt to every language
for (int l = 0; l < 56; l++) {
double current_lang_score = 0;
for (int i = 0; i < 100; i++) {
// We add the count of how many times symbol E[i]
// has appeared in language 'l' so far.
current_lang_score += freq[l][E[i]];
}
if (current_lang_score > max_score) {
max_score = current_lang_score;
best_lang = l;
}
}
// 2. GUESSING PHASE: Submit our best guess to the grader
// This function returns the ACTUAL correct language
int true_lang = language(best_lang);
// 3. LEARNING PHASE: Update our frequency table with the truth
for (int i = 0; i < 100; i++) {
freq[true_lang][E[i]]++;
}
}