Primer 3

  1. A function to determine if a point is inside a rectangle.

     in_box :: Posn -> Posn -> Posn -> Bool
     in_box lower_left upper_right p = False
    
     check_in_box = [ in_box (0,0) (4,8) (3,7),
                        not $ in_box (10,20) (15,30) (5,8) ]
    

2.A function to deterine if all of the points in a list are in a rectangle.

    all_in_box :: Posn -> Posn -> [Posn] -> Bool
    all_in_box lower_left upper_right ps = False

    check_all_in_box = [ all_in_box (0,0) (4,8) [(2,3),(4,6)],
                         not $ all_in_box (0,0) (4,8) [(1,4),(5,2)(0,7)],
                         not $ all_in_box (10,0) (15,9) [(14,10), (11,5)]]
  1. A function that takes in lists of points and only keeps the ones in which all of the points are in the box.

     keep_all_in_box :: Posn -> Posn -> [[Posn]] -> [[Posn]]
     keep_all_in_box lower_left upper_right pts = []
    
     check_keep_all = [
         keep_all_in_box (0,0) (4,5)
              [[(1,3),(2,5)],
               [(3,6),(0,4)],
               [(2,1),(9,3),(4,5)],
               [(0,0),(1,0),(2,0),(3,0),(4,0)]]
              ==
              [[(1,3),(2,5)],
               [(0,0),(1,0),(2,0),(3,0),(4,0)]]
          ]
    
Last modified August 18, 2023: 2022-2023 End State (7352e87)