Question
search_util.c 3.56 KB Edit Web IDE Replace Delete 1 #include search_util.h 2 3 4 #include #include #include #include 5 6 7 8 9 10 11
search_util.c 3.56 KB Edit Web IDE Replace Delete 1 #include \"search_util.h\" 2 3 4 #include #include #include #include 5 6 7 8 9 10 11 // This function should loop over the vocabulary (which contains num_words // entries) and return the number of words in which that particular Letter // occurs. So if there are 15 words containing the letter 'x' for the particular // vocabulary, then this function will return 15. int score_letter(char letter, char **vocabulary, size_t num_words) { 12 13 14 15 16 // TODO(you): implement this function! return 0; 17 18 } 19 20 21 22 23 24 25 26 27 28 // Calculate the score for a given word, where the letter_scores array has // already been filled out for you and is guaranteed to be of Length 26. Slot o // contains the score for 'a', and slot 25 contains the score for 'z'. // The score for a word is the sum of all of the letter scores, *for unique // Letters*. So if the Letter 'e' occurs three times, it only contributes to the // score once. int score_word (char *word, int *letter_scores) { 27 int score_word char *word, int *letter_scores) { 28 29 // TODO(you): implement this function! return 0; 30 31 32 } 33 34 35 36 // Returns the optimum guess, based on our heuristic. // This one works, you don't have to change it. // Note that this function allocates a new string every time it runs, and those // strings will need to be freed! char *get_guess (char **vocabulary, size_t num_words) { int letter_scores [26]; 37 38 39 40 41 42 for (int i = 0; i best_score) { best_guess = vocabulary[i]; best_score = score; } } return best_guess ? strdup (best_guess) : NULL; } 53 54 55 56 57 58 59 60 61 // This function will filter down the vocabulary based on the knowledge that the // specified Letter *does not occur* in the secret word. So for any of the words 62 61 62 63 64 // This function will filter down the vocabulary based on the knowledge that the // specified Letter *does not occur in the secret word. So for any of the words // in the vocabulary that do contain that letter, free their pointers and set // the corresponding slot to NULL. // Returns the number of words that have been filtered from the vocabulary. size_t filter_vocabulary_gray(char letter, char **vocabulary, size_t num_words) { 65 66 67 68 69 // TODO (you): implement this function! return; 70 71 72 } 73 74 75 76 77 // This function will filter down the vocabulary based on the knowledge that the // specified Letter occurs in the word, but not at this particular position*. // So remove any words that either don't contain the Letter at all, or do // contain it, but at the specified position. // Returns the number of words that have been filtered from the vocabulary. size_t filter_vocabulary_yellow(char letter, int position, char **vocabulary, size_t num_words) { 78 79 80 81 82 // TODO (you): implement this function! return 0; 83 84 85 } 86 87 88 89 90 // This function will filter down the vocabulary based on the knowledge that the Il specified Letter *definitelyt occurs as the specified position. So remove any // word that does not contain, for the specified position, the specified Letter. // Returns the number of words that have been filtered from the vocabulary. size_t filter_vocabulary_green(char letter, int position, char **vocabulary, size_t num_words) { 91 92 93 94 95 // TODO (you): implement this function! return; 96 96 return; 97 98 } 99 100 101 102 103 // Free each of the strings in the vocabulary, as well as the pointer vocabulary // itself (which points to an array of char *). void free_vocabulary(char **vocabulary, size_t num_words) { for (size_t i = 0; i #include #in\" v:shapes=\"Picture_x0020_61\">
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started