Due Tuesday 30-Jan, at 9:00pm
hw3.py
file includes test functions to help you test on your own before
you submit to Gradescope. When you run your file, problems will be tested in order. If
you wish to temporarily bypass specific tests (say, because you have not yet completed
some functions), you can comment out individual test function calls at the bottom
of your file in main()
. However, be sure to uncomment and test everything together
before you submit! Ask a CA if you need help with this.Do not convert strings to lists, use lists or recursion this week. The autograder (or a manual CA review later) will reject your submission entirely if you do.
Starting with this assignment, we will be grading your code based on whether it follows the 15-112 style guide. We may deduct up to 10 points from your overall grade for style errors. We highly recommend that you try to write clean code with good style all along, rather than fixing your style issues at the end. Good style helps you code faster and with fewer bugs. It is totally worth it. In any case, style grading starts this week, so please use good style from now on!
You will notice that the skeleton file only includes testcases for some of the functions you are writing. You should write testcases for the others. (You can find some nice ways to test in the write-up below, but you will need to translate those to actual testcases.)
rotateStringLeft(s, n)
that takes a string s and a
possibly-negative integer n. If n is non-negative, the function
returns the string s rotated n places to the left.
If n is negative, the function
returns the string s rotated |n| places to the right. So, for example:
isRotation(s, t)
that takes two possibly-empty strings and returns True if one is a rotation of the other. Note that a string
is not considered a rotation of itself.mostFrequentLetters("We Attack at Dawn")returns "atwcdekn". Note that digits, punctuation, and whitespace are not letters! Also note that seeing as we have not yet covered lists, sets, maps, or efficiency, you are not expected to write the most efficient solution. (And you should not use lists, sets, or maps in your solution.) Finally, if s does not contain any alphabetic characters, the result should be the empty string ("").
text
your task is to find the most frequently
occuring substring of a given length. In the event of a tie between two substrings, choose the one that comes later in the alphabet. (So "bbb" is chosen over "bba".)
Consider the following example in which the length is three (n
= 3) and the text is
just baababacb
. The most frequent substring would then
be aba
because this is the substring with size 3 that appears most
often in the whole text (it appears twice) while the other six different
substrings appear only once (baa ; aab ; bab ; bac ; acb)
. You can
assume length >= 0
. Here are more examples:
Function call: encodeColumnShuffleCipher("WEATTACKATDAWN", "1320") Message: WEATTACKATDAWN Key: 1320 Initial Grid: Rearranged Grid: W E A T T W A E T A C K K T C A A T D A A A D T W N - - - W - N Encrypted Message: TKA-WTAWACD-EATN Message to Return: 1320TKA-WTAWACD-EATNThe first step is to take the message and arrange it into a grid that has as many columns as the key has characters. (In this case, 4 columns.) Any empty spaces at the end are filled with - characters. We then rearrange the grid by changing the column order to match the order specified by the key. In this case, 0 being in the 3rd position of the key tells us that the 3rd column will become the 0th column. 1 being in the 0th position tells us that the 0th column will become the 1st column. 2 being in the 2nd position tells us that the 2nd column will become the 2nd column. 3 being in the 1st position tells us that the 1st column will become the 3rd column.