Below you will find pages that utilize the taxonomy term “rectangle”
Posts
Rectangle counting
The problem is to count the number of rectangles (aligned to x and y coordinates) that can be formed by a set of points. Answer from competitive programmer Errichto.
def num_rect(points): m = defaultdict(lambda: 0) answer = 0 for p in points: for p_above in points: if p.y < p_above.y: answer += m[(p.y,p_above.y)] m[(p.y,p_above.y)] += 1 return answer Consider the following set of points:
x x x 1 2 3 This is for k = 3, there are 3 possible rectangles.