CMU 15-112: Fundamentals of Programming and Computer Science
Homework 11 (Due Saturday 30-Jul at 8pm ET)
Important notes about hw11 bonus:
- hw11 bonus will be submitted separately in Autolab, in hw11-bonus (in the etc category).
- There is no starter file for hw11-bonus.
- With that, have fun!!! >>( o u o )<<
- As usual, this homework is solo. You must not collaborate with anyone (besides current course TA's and faculty) in any way. See the syllabus for more details.
- To start:
- Create a folder named 'hw11'
- Download all of these to that folder, and note that we are using week 5's linter for this assignment:
- Edit hw11.py
- When you have completed and fully tested hw11, submit hw11.py to Autolab. For this hw, you may submit up to 5 times, but only your last submission counts.
- Do not hardcode the test cases in your solutions.
A few more notes:
- You may (and in fact must) finally use recursion this week.
- Every problem this week requires that you use recursion meaningfully in order to receive the points. The assignment will be autograded, but we may manually review submissions and apply deductions to solutions with iterative or otherwise prohibited components.
- You also may not use loops -- no
for
loops orwhile
loops this week! - You may (but do not need to) use helper functions, so long as they are not iterative.
- You may (but do not need to) use wrapper functions -- that is, your solution function may itself be a non-recursive (but also non-iterative) function a recursive helper function. See recursion notes for more details.
- You may only use builtin functions or methods if they run in O(1). So in particular, among many other builtins you may not use this week, you may not use sum, sort, sorted, count, min, or max this week (you can write your own recursive versions of these if you wish, though that is not required, and we did not do that for our sample solutions). Also, note that slicing (L[i:j]) is just fine this week.
Homework 11 Overview:
- Recursion-Only oddCount(L) [25 pts]
- Recursion-Only oddSum(L) [25 pts]
- Recursion-Only oddsOnly(L) [25 pts]
- Recursion-Only maxOdd(L) [25 pts]
- Bonus/Optional: Recursion-Only Recursive Tetris! [3 pts]
- Recursion-Only oddCount(L) [25 pts] [autograded]
Without using iteration, write the recursive function oddCount(L) which given a possibly-empty list L of integers, returns the number of odd integers in L. - Recursion-Only oddSum(L) [25 pts] [autograded]
Without using iteration, write the recursive function oddSum(L) which given a possibly-empty list L of integers, returns the sum of the odd integers in L. Return 0 if the list has no odd integers in it.
Note: You may not simply create a new list of just the odd numbers and find the sum of that list. Your solution should only need to read each element in the list once. - Recursion-Only oddsOnly(L) [25 pts] [autograded]
Without using iteration, write the recursive function oddsOnly(L) which given a possibly-empty list L of integers, returns a new list containing only the odd integers in L in the same order they appear in L. - Recursion-Only maxOdd(L) [25 pts] [autograded]
Without using iteration, write the recursive function maxOdd(L) which given a possibly-empty list L of integers, returns the largest odd integer in L, or None if L does not contain any odd integers. - Bonus/Optional: Recursion-Only Recursive Tetris! [3 pts] [manually graded]
For bonus this week, submit a new entirely-recursive version of Tetris to hw11-bonus (a separate assignment on autolab). You may start from the Tetris code you submitted for hw9, but then convert it to be entirely recursive. No loops, and no built-ins unless they run in O(1)!