CMU 15-112 Summer 2020: Fundamentals of Programming and Computer Science
Collab 11 (Due Thu 11-Jun, at 11:59pm)




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

  2. generateLetterString(s string) string [20pts]
    Write the function generateLetterString(s string) string 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.