CMU 15-112 Summer 2020: Fundamentals of Programming and Computer Science
Collab 11 (Due Thu 11-Jun, at 11:59pm)
- This assignment is COLLABORATIVE. This means you may work with your week's collaboration group within the course collaboration boundaries. See the syllabus for details.
- To start:
- Create a folder named 'collab11'
- Download collab11.go
- Edit collab11.go using VSCode
- When you are ready, submit collab11.go to Autolab. For this hw, you may submit up to 10 times, but only your last submission counts.
- You may finally (and in fact must) use recursion in this assignment!
- Do not hardcode the test cases in your solutions.
- NOTE: For the next few days, assignments in Go will be manually graded.
- You must use recursion to solve these problems. Using a for or while loop will result in you losing full credit for the question. You may also not use inherently iterative functions. These include range, sum, max, min, count, replace, sort, reverse, sorted, and reversed.
- 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.
- 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.