type PointsList = (int*int) list
let diagonals (points : PointsList) (pX, pY) : PointsList =
|> List.filter(fun (x,y) -> (x > pX && y > pY))
let topLeft (p1X, _) (_, p2Y) = (p1X, p2Y)
let bottomRight (_, p1Y) (p2X, _) = (p2X, p1Y)
let numberOfRectangles (points : (int*int) list) =
let contains (p : int*int) = points |> List.exists ((=) p)
|> List.collect(fun p -> diagonals points p |> List.map(fun d -> (p, d)))
|> List.filter(fun (bL, tR) -> contains (topLeft bL tR) && contains (bottomRight bL tR))