CMU 15-112 Summer 2018: Fundamentals of Programming and Computer Science
Homework 10 (Due Wed 13-Jun, at 5pm)




  1. recursive alternatingSum(lst) [30 pts]
    Write the function alternatingSum(lst) that takes a possibly-empty list of numbers, lst, and returns the alternating sum of the list, where every other value is subtracted rather than added. For example: alternatingSum([1,2,3,4,5]) returns 1-2+3-4+5 (that is, 3). If lst is empty, return 0.


  2. recursive powersOf3ToN(n) [30 pts]
    Write the function powersOf3ToN(n) that takes a possibly-negative float or int n, and returns a list of the positive powers of 3 up to and including n, or None (not an empty list) if no such values exist. As an example, powersOf3ToN(10.5) returns [1, 3, 9].


  3. recursive generateLetterString [40 pts]
    Write the function generateLetterString(s) that takes a two-character string and returns a new string that contains the all of the letters between the first letter and the second letter. For example, generateLetterString("ko") would return "klmno". This should also work backwards, so generateLetterString("me") would return "mlkjihgfe". If the initial provided string is not two characters long you should return the empty string. If the string contains two identical characters (like "aa"), then return the letter ("a"). You may assume that you are given only lowercase letters.