Problem Set 2
Home Up Problem Set 1 Problem Set 2 Problem Set 3 Problem Set 4 Problem Set 5 Problem Set 6 Problem Set 7 Problem Set 8 Problem Set 9 Problem Set 10 Final Project

 

Due 5PM Friday, September 17.

Chapter 5:

  1. Exercise 5.3 in SOE.
     
  2. Exercise 5.5 in SOE.  You should, of course, use higher-order functions rather than direct recursion in solving these.
     
  3. Exercise 5.7 in SOE.
     
  4. Exercise 5.9 in SOE.  Note that the straightforward solution to this problem is not necessarily optimal for all sets of coin values.  For example, making change for an amount 6 given coin values [4,3,1] is better solved as [0,2,0] rather than [1,0,2].  You are not required to give the optimal solution, but feel free to do so if you wish.

Chapter 6:

  1. Define a function squares :: Int -> [Int] such that squares n returns a list of all perfect squares less than or equal to n.  For example, squares 50 returns [1,4,9,16,25,36,49].  Do not use direct recursion.
     
  2. Using the function iterate from the Standard Prelude (and possibly some other higher-order functions that we have already discussed), define a function intSeq :: Int -> Int -> Int -> [Int] such that intSeq a b c is equivalent to [a, b .. c].

 

Solutions