If you have actually an **n **x **m **grid, how countless squares have the right to you shade inside the grid. For example, a 2x3 grid has actually 8 squares in that as shown below:

Solution

The cheat to solving this concern (or this kind of inquiry for that matter) is patience. You have to break the difficulty into smaller pieces or less complicated parts and also then shot to generalize her answer.

You are watching: How many squares are in this 2×2 grid

Since a 2x3 grid has the same variety of squares as a 3x2 grid, I chose to do my life easier and also reword the inquiry to “number the squares in one nxm grid where m >= n”.

Since n is constantly smaller than m, we can also conclude that our net will have actually at many squares of dimension **n **x **n. **Therefore we need to sum the number squares of size 1x1 + 2x2 + … + n x n.

Starting v the simplest situation here, a 1x1 grid has actually 1 square. It is likewise easy to view that a 1 x **m **grid has actually **m (**or 1*m) 1x1 squares.

a 2**x2 grid **has 4 1x1 squares and also a single 2x2 square = 5.

a 2**x3 grid **has 6 1x1 (2 * 3) squares and also 2 2x2 (2 * 1) squares = 8. (we addressed this above.)

If you continue this girlfriend can quickly see that a 2 **x m net **has 2*m + 1*(m — 1) squares in it. Let’s move on come the next step!!

a 3**x3 net **has 9 1x1 (3 * 3) squares 4 2x2 (2 * 2) squares and also a solitary 3x3 square = 14.

a 3**x4 grid **has 12 1x1 (3 * 4) squares 6 2x2 (2 * 3) squares and also 2 3x3 squares = 20.

Again, if you proceed this girlfriend can discover that a 3 **x m grid **has 3*m + 2*(m-1) + 1*(m-2) squares. At this allude if you compare our an outcome for 3xm and 2xm you can see a pattern. So let’s generalize ours solution.

an **n x m grid **has n*m + (n-1)*(m-1) + (n-2)*(m-2) + … + (n-(n-1))*(m-(n-1)) squares. Because I have actually just began to find out the walk Language, it to be a perfect exercise for me to compose a regimen to fix this question, I’ve consisted of the source below.

See more: How Many Cups In 6 Oz Of Flour? What Does 6 Ounces Equal In Cups

/** * I'm making use of my own versions of max and min since * mathematics package only has actually max() float64 and min() float64 */func max (a,b int) int if a > b return a rather return b return 0func min (a,b int) int if a return a rather return b return 0}func count(n, m int) int s, b := min(n, m), max(n, m) r := 0 for i := 1; i r += (s - ns + 1) * (b - i + 1) return r}func main() fmt.Print(count(2,3));FunWhile playing with the count() duty I witnessed that 4 x m has actually a an extremely interesting pattern!

4x3 = 20 4x4 = 30 4x5 = 40 4x6 = 50 4x7 = 60 4x8 = 70 4x9 = 80// guess: v what is the next value!To challenge yourself shot and settle the exact same question except with rectangles! i.e. “How many rectangles space there in an n x m grid?”.