Straight Line Through A Grid

If we draw a line connecting the corners of a 5 × 8 5 \times 8 square grid, how many 1 × 1 1 \times 1 squares does it cut through?

10 11 12 13

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.

1 solution

Chung Kevin
Aug 16, 2016

If you look at the image and count, you will get that the answer is 12. How can we generalize the result?

Look at the line. When does it enter a new square? It enters a new square whenever it crosses a grid line, whether vertically or horizontally. It starts out (in the corner) of a square, and then it has to cross 4 + 7 4 + 7 grid lines, before ending in the corner of the rectangle. Thus, it will go through 1 + 4 + 7 = 12 1 + 4 + 7 = 12 squares.

More generally, for a m × n m \times n grid, where gcd ( m , n ) = 1 \gcd (m,n) = 1 , then the line will not hit any other corners, and hence each time it crosses a gridline, it will go into a new square. Thus, the number of squares is 1 + ( m 1 ) + ( n 1 ) = m + n 1 1 + (m-1) + (n-1) = m+n - 1 .

How do we deal with the case where gcd ( m , n ) 1 \gcd (m,n) \neq 1 ?

Let gcd (m,n)=a.

Since a corner counts as entering 1 new box but crosses both a vertical and horizontal line, we must subtract 1 from our original m+n-1 for each corner.

Since the starting point does not count towards this, we can ignore that one, but the ending point is counted so must use one less than the number of corners (which is represneted by the gcd).

Thus the general form for any gcd (m,n)=a is: m+n-1-(a-1) = m+n-1-a+1=m+n-a

Seth Christman - 4 years, 10 months ago

Log in to reply

I agree with the initial logic, but the final formula seems incorrect. For example, in a 2 by 2 grid, we cross just 2 squares, but your formula gives 2 + 2 + 2 2 = 4 2 + 2 + 2 - 2 = 4 .

Chung Kevin - 4 years, 10 months ago

Log in to reply

You are correct! I realized this mistake earlier. I have edited my error.

Seth Christman - 4 years, 10 months ago

Log in to reply

@Seth Christman That's right now :)

Chung Kevin - 4 years, 9 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...