Number of rectangles

Find the number of rectangles that can be formed from the gridlines of the board as shown in the figure above.


This is a part of the Set .


The answer is 509.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Bill Bell
Sep 9, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
from itertools import product, combinations

columns=range(1,7)
rows=range(1,11)

lattice=[point for point in product(rows,columns)]
lattice.remove((1,1))
lattice.remove((2,1))
lattice.remove((9,6))
lattice.remove((10,6))

def isRectangle(points):
    xCoords=set(p[0] for p in points)
    yCoords=set(p[1] for p in points)
    return len(xCoords)==2 and len(yCoords)==2 

count=0
for points in combinations(lattice,4):
    count+=isRectangle(points)
print count

It was finished in a twinkling. The script builds the full rectangular lattice then removes the four points at the corners. Then it samples 4-combinations of lattice points. It tests whether the four points form a rectangle by calculating the sizes of their sets of x- and y-coordinates.

Tianle Deng
Jan 5, 2019

Well I am a novice from a neighborhood secondary school, so please forgive me if I've made any mistake! But I think I have a way to answer:

First we count a 5 9 "chess" board (i.e. we abandon the two cut corners) . Using the idea in one MindYouDecision video (something like four lines determine an unique rectangle) , the number of rectangles = 10C2 6C2=15 45. Then we need to subtract. Let's to the top left corner first. Of course one side of the rectangles we must subtract lies on the left edge and another side at top edge or second from top edge. After some work we find out that the number we need to subtract = 5 (8+9). The bottom right is the same thing. But we've counted twice some rectangles. Those rectangles' two opposite sides are the left and right edges, and another pair of their opposite sides are one of top 2 horizontal lines and one of bottom two horizontal lines, respectively. So we see there are 4 such rectangles. So we put everything together: 15 45-2 [(8+9)*5]+4 = 509.

I know my language is pretty bad, but I am not very good at explainning. Besides I don't have much time!

Why are some "*" not shown?

Tianle Deng - 2 years, 5 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...