"it all starts with a dictionary each letter of the alphabet is included as a key and…
- User
"it all starts with a dictionary each letter of the alphabet is included as a key and maps to a list with five numbers. These numbers represent each position in a five letter word we then iterate over all the letters in the dictionary and all the possible words left recording the frequencies of occurrence of each letter in each position into the dictionary here's an example let's say we have a word consisting of five a's since this word only contains a we will only need to update the frequencies in the dictionary for a the frequency for each position is increased by one let's now consider a second word x y z a a seems like a good choice for letter a we need to update the dictionary we now have one one one two two we must also update the values for x and the other occurring letters once we have iterated over all words we have frequencies for each letter next we find the maximum frequency for each position from 0 to 4 for the whole alphabet this happens in the first for loop of the code shown the second for loop calculates a score for each word this score is calculated by multiplying the frequency differences from the maximum for each letter and position in a given word the word with the lowest score is best but why does this give the best word well by maximizing similarity with the other possible words we ensure the set of possible words is minimized with each guess that's pretty neat now we know how this works we need a way to test it so i wrote another script to iterate over all the word all target words and to find the mean number of guesses my algorithm takes i should also note that my code removes words that have come up previously with this the mean number of guesses is 2.95 so less than three this project was inspired by three blue one brown if you enjoyed it please check out some of my other projects where i do a lot more than just coding [Music]" Help me to add the punctuations to the above script.
- Assistant
Sure, I'll add the necessary punctuation to your script to make it clearer and more readable. Here's the revised version:
"It all starts with a dictionary. Each letter of the alphabet is included as a key and maps to a list with five numbers. These numbers represent each position in a five-letter word. We then iterate over all the letters in the dictionary and all the possible words left, recording the frequencies of occurrence of each letter in each position into the dictionary. Here's an example: let's say we have a word consisting of five 'a's. Since this word only contains 'a', we will only need to update the frequencies in the dictionary for 'a'. The frequency for each position is increased by one.