returns: list of tuples. each tuple is (position in text, amount of
recursion again?). The non-recursive version of this function is much more difficult to
unnecessary parameter “start”. As always with recursion, you should begin by thinking about
your base case, the simplest possible sub-problem you will need to solve. What value of start
would make a good base case? (Hint: the answer is NOT zero.)
To help you test your code, we’ve given you two simple helper functions:
random_string(wordlist, n) generates n random words from wordlist and returns them in a string.
random_scrambled(wordlist, n) generates n random words from wordlist and returns them in a
string after encrypting them with a random multi-level Caesar shift. You can start by making
sure your code decrypts a single word correctly, then move up to 2 and higher.
NOTE: This function depends on your implementation of apply_shifts, so it will not work
correctly until you have completed Problem 3.
def find_best_shifts_rec(wordlist, text, start):
"""
Given a scrambled string and a starting position from which
to decode, returns a shift key that will decode the text to
words in wordlist, or None if there is no such key.
Hint: You will find this function much easier to implement
if you use recursion.
wordlist: list of words
text: scambled text to try to find the words for
start: where to start looking at shifts
returns: list of tuples. each tuple is (position in text, amount of
shift)
"""
### TODO.
Dostları ilə paylaş: