5 kyu

Count Rectangles

Description:

Given a list/array of points on a quadratic grid, count the rectangles whose vertices are all in the given list.

The coordinates are non-negative integers (0 inclusive) bounded by 100. The axes of the coordinate system are orthogonal and equally scaled. The sides of a rectangle need not be horizontal or vertical.

Example 1:

Given the points

[(0, 0), (0, 1), (0, 2),
 (1, 0), (1, 1), (1, 2),
 (2, 0), (2, 1), (2, 2)]

There a 10 rectangles whose vertices are in this list. Nine rectagles have their sides aligned with the axes of the coordinate system, and the last rectangle is the one with coordinates (0, 1), (1, 0), (2, 1), (1, 2): svg image Example 2:

Given the points

[(1, 0), (4, 0),
 (1, 1), (3, 1), (9, 1),
 (0, 2), (4, 2), (5, 2), (6, 2), (9, 2),
 (2, 3), (5, 3), 
 (1, 4), (2, 4), (4, 4), (5, 4), (9, 4)]

There are 12 rectangles whose vertices are in the given list, as shown in the figure: svg image The vertices of these rectangles are:

((3, 1), (1, 0), (0, 2), (2, 3))
((0, 2), (1, 0), (5, 2), (4, 4))
((0, 2), (4, 0), (5, 2), (1, 4))
((1, 0), (4, 0), (4, 4), (1, 4))
((4, 0), (3, 1), (5, 3), (6, 2))
((4, 0), (1, 1), (2, 4), (5, 3))
((1, 1), (9, 1), (9, 4), (1, 4))
((3, 1), (5, 2), (4, 4), (2, 3))
((4, 2), (5, 2), (5, 4), (4, 4))
((4, 2), (9, 2), (9, 4), (4, 4))
((5, 2), (9, 2), (9, 4), (5, 4))
((5, 3), (2, 3), (2, 4), (5, 4))

The most complex tests will randomly select approximately 15% of the points in a 50-by-100 grid. The result will typically be in the thousands.

Puzzles
Algorithms

Stats:

CreatedNov 28, 2019
PublishedNov 28, 2019
Warriors Trained280
Total Skips103
Total Code Submissions144
Total Times Completed26
Python Completions26
Total Stars14
% of votes with a positive feedback rating94% of 8
Total "Very Satisfied" Votes7
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes0
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • ecolban Avatar
  • dfhwze Avatar
Ad