In which dad attempts to explain what the teacher was going on about when discussing map#4
In which dad attempts to explain what the teacher was going on about when discussing map#4nickmarden wants to merge 1 commit intomasterfrom
Conversation
nickmarden
commented
Oct 31, 2017
dbe83d7 to
77b855e
Compare
…when discussing map
77b855e to
a792974
Compare
| if x == max(freqall): | ||
| print(''.join(decrypt)) | ||
|
|
||
| decrypted_strings = [] |
There was a problem hiding this comment.
First: generate the "decrypted" list of characters for each of the 26 possible shift values. We will use this later.
| best_score = 0 | ||
| best_score_shift = 0 | ||
|
|
||
| for shift in range(26): |
There was a problem hiding this comment.
Now, for each entry in the list of possible decrypted strings, compute the frequency_score for that string.
Each step along the way, if the frequency score that we are looking at now is better (higher) than any score we have seen so far, then it is the "best" frequency score and we want to record it as such. We need to record it so that we can know whether the next or the next or the next decrypted string is "better" or not.
Also, we keep track of the "shift" value associated with the best score, so that we can actually pluck that decrypted string out of the decrypted_strings list at the end of the exercise. Alternatively we could take your approach like this:
for x in decrypted_strings:
if frequency_score(x) == best_score:
print(''.join(x))
But that seemed clunkier to me than simply recording the list index of the best-scoring string, at the moment when we discover that it is the best-scoring string.