Chapter 4 Discussion IV

A few practice problems from a review session.
  1. Target. tgt :: Int -> [Int] -> Int. Given a target number and a list of numbers, find the smallest distance between the target number and any number in the list.

    tgt 5 [3,8,10,4]  == 1
    tgt 6 [10,4,30,50,9]  == 2
    
  2. Take in an ordered pair (x,y) and a list of floating point ws. Find out if the ordered pair is on the graph of y=x^3 with x also being one of the ws. Return true if it is, false if not.

    onGraph (5,125) [1,5,10] == True
    onGraph (2,8) [1,3,4] == False
    onGraph (3,12) [1,3,4] == False
    
  3. Splash. Inputs: a list of ordered pairs and a point (one ordered pair). Output: All ordered pairs in the list within distance 10 of the point.

Last modified September 18, 2023: Some rewording (605fb98)