15-112: Fundamentals of Programming and Computer Science
Week 2 Practice Problems
- Suggested problems for 1-Hour Group Study Sessions (see hw2 for details)
- Covered in Recitation
- Review lecture notes, especially covering break/continue, isPrime, fasterIsPrime, and nthPrime
- Happy Primes from here
- Counting Primes also from here
- sumOfFunctionToN:
First, very briefly discuss first-class function values (functions as arguments). Then, to demonstrate, write the function sumOfFunctionToN(f, n) that takes
a function f and a non-negative int n, and returns the sum f(1)+f(2)+...+f(n). Use that function, along well-chosen
very short helper functions, to find the sum of the squares to 100 (that is, 1**2 + 2**2 + ... + 100**2, which is 338,350) and the sum of the cubes to 100 (that is, 1**3 + ... + 100**3, which is 25,502,500).
- More problems from additional suggested practice (see below)
- Additional suggested practice