SQL (POSTGIS), <s>286</s> <s>269</s> 261 -- This is a query for the PostGIS extension to PostgreSQL. I haven't counted the input values in the total. WITH I AS(SELECT*FROM(VALUES -- Coordinate input (2, 1, 3, 11) ,(1, 10, 5, 19) ,(6, 10, 11, 3) ,(8, 8, 15, 15) ,(13, 13, 9, 5) ,(15, 1, 19, 7) ,(17, 19, 19, 17) )i(a,b,c,d))SELECT COUNT(*)FROM(SELECT(ST_Dump(ST_polygonize(g))).geom d FROM(SELECT ST_Union(ST_ExteriorRing(ST_MakeEnvelope(a,b,c,d,0)))g FROM i)a)b WHERE ST_Area(d)=(ST_XMax(d)-ST_XMin(d))^2AND ST_Area(d)=(ST_YMax(d)-ST_YMin(d))^2 **Explanation** The query builds geometries for each coordinate pair. Unions the exterior rings to properly node the lines. Turns the results into polygons and tests <s>the width against height and</s> the area against each side squared. It will run as a standalone query on any PostgreSQL database with the PostGIS Extension.