CMU 15-112 Spring 2016 Quiz8 Practice
(Due never)
- Quiz8 will include a subset of the problems here.
- Recursion Notes Examples
- sumOfOdds(L) (recursive)
- hasConsecutiveDigits(n) (recursive)
- min(L) (recursive)
- isPerfectNumber(n) (recursive)
- betterDotsDemo() (with OOP)
-
Recursion Notes Examples
You should understand all the worked examples in
these notes:
- digitSum(n)
- fib(n)
- gcd(x,y)
- factorial(n)
- isPrime(n) and nthPrime(n)
- vowelCount(s)
-
sumOfOdds(L) (recursive)
Without using iteration, write the recursive function sumOfOdds(L) that
takes a list of integers and returns the sum of the odd numbers in that list.
-
hasConsecutiveDigits(n) (recursive)
Without using iteration, write the recursive function
hasConsecutiveDigits(n) that takes a possibly- negative int value n and returns True if that number contains two consecutive digits that are the same, and False otherwise.
-
min(L) (recursive)
Without using iteration, and without using the builtin min function or any
other similar builtin function, write the recursive function min(L) that takes
a list L of integers and returns the minimum value in the list.
-
isPerfectNumber (recursive)
Without using iteration, write the recursive function
isPerfectNumber that takes a possibly-negative integer n and returns
True if it is a perfect number and False otherwise,
where a number is perfect if it is the sum of its positive divisors less than itself. For example, 6 is perfect because 6 = 1 + 2 + 3. Also, 28 is perfect because 28 = 1 + 2 + 4 + 7 + 14. The next one is 496, then 8128.
-
betterDotsDemo (with OOP)
You should be very clear on how to convert dotsDemo into betterDotsDemo,
as covered in lecture (and in
these notes).