CMU 15-112 Spring 2017: Fundamentals of Programming and Computer Science
Lab 3 (Due Thursday 14-Sep, at 10pm)

This lab has 2 required forms -- one to make groups and one to peer-review each others' groupwork (in terms of being great groupmates, not in terms of getting right answers).

Reminder: do not work on these problems alone -- only work on them together with your lab partners!

  1. longestCommonSubstring(s1, s2) [25 pts]
    Write the function, longestCommonSubstring(s1, s2), that takes two possibly-empty strings and returns the longest string that occurs in both strings (and returns the empty string if either string is empty). For example:
         longestCommonSubstring("abcdef", "abqrcdest") returns "cde"
         longestCommonSubstring("abcdef", "ghi") returns "" (the empty string)
    If there are two or more longest common substrings, return the lexicographically smaller one (ie, just use "<" to compare the strings). So, for example:
        longestCommonSubstring("abcABC", "zzabZZAB") returns "AB" and not "ab"

  2. bestStudentAndAvg(gradebook) [30 pts]
    Background: for this problem, a "gradebook" is a multiline string where each row contains a student's name (one word, all lowercase) followed by one or more comma-separated integer grades. A gradebook always contains at least one student, and each row always contains at least one grade. Gradebooks can also contain blank lines and lines starting with the "#" character, which should be ignored.

    With this in mind, write the function bestStudentAndAvg(gradebook), that takes a gradebook and finds the student with the best average (ignoring the case where there is a tie) and returns a string of that student's name followed by a colon (":") followed by his/her average (rounded to the nearest integer). For example, here is a test case:
    gradebook = """
    # ignore  blank lines and lines starting  with  #'s
    assert(bestStudentAndAvg(gradebook) ==  "wilma:92"))
    Note: you most likely will want to use both s.split(",") and s.splitlines() in your solution.

  3. encodeColumnShuffleCipher(message, key) [40 pts]
    Background: In this problem you will implement a simple encryption cipher we've called a column shuffle cipher. It takes two values, a plaintext and a key, and it constructs a grid of the letters of the message, rearranges the columns of the grid, and then reads the characters back column by column.

    Consider the following example:
    Function call: encodeColumnShuffleCipher("WEATTACKATDAWN", "0213")
    Key: 0213
    Initial Grid:		Rearranged Grid:
    W E A T			W A E T
    T A C K			T C A K
    A T D A			A D T A
    W N - -			W - N -
    Encrypted Message: WTAWACD-EATNTKA-
    Message to Return: 0213WTAWACD-EATNTKA-
    The 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, the 0th column becomes first, then the 2nd column, then the 1st, and then the 3rd. Finally, we read out the encrypted message by reading down the columns from left to right. The returned value from the function is just the encrypted message prepended with the key.

    With this in mind, write the function encodeColumnShuffleCipher(message, key) that takes an all-uppercase message and a valid key, and returns the encoding as just described.

    Hint: In your program you won't actually build a grid. Instead, you will use the concept of the grid to help you calculate the index of individual characters in your message.