Counting Squares

Let us count the number of distinct shapes that can be formed using n n unit squares that are connected side to side. We consider rotations and reflections to be the same shape.

Consider the above image:
If we have 1 square, then it can only form 1 distinct shape.
If we have 2 squares, then it can only form 1 distinct shape.
If we have 3 squares, then it can form 2 distinct shapes.
If we have 4 squares, then they can form 5 distinct shapes. These are the straight line, the L-shape, the T-shape, the S-shape, and the box, which we see in a game of Tetris.

How many distinct shapes can be formed if we have 10 Squares ?


The answer is 4655.

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.

5 solutions

Danny Whittaker
Apr 15, 2014

This doesn't seem to be a combinatorics question, but more a computer science question. How to calculate this without writing a program or just look it up via Google is beyond me. If the question asked for the number for 5 squares or even 6 squares, then it would be doable.

Akshat Sharma
Apr 23, 2014

A polyomino is a plane geometric figure formed by joining one or more equal squares edge to edge. It is a polyform whose cells are squares. It may be regarded as a finite subset of the regular square tiling with a connected interior.

1 monomino 1
2 domino 1
3 tromino 2
4 tetromino 5
5 pentomino 12
6 hexomino 35
7 heptomino 108
8 octomino 369



9 nonomino 1,285

10 decomino 4,655

11 undecomino 17,073
12 dodecomino 63,600

Can you explain more clearly????what this -mino is...

Ashwani Singh Tanwar - 6 years, 8 months ago

Is it following some mathematical pattern !!!!

Raj Gopal - 6 years, 8 months ago

Log in to reply

https://oeis.org/A000105

Anatoliy Razin - 6 years, 6 months ago
Anand K
May 25, 2014

I wrote a C++ program to solve this. It is fun to solve it as a computer science question. But is there a mathematical solution?

Care to post your solution?

Peter Byers - 6 years, 10 months ago

Seriously, can you post your solution?

Nitesh Asthana - 6 years, 9 months ago
Laurent Shorts
Apr 27, 2016

We can just look at A000105

Here's a python program, but it is not very efficient:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def getAvailablePositions(points):
        positions = []
        for p in points:
                for (dx,dy) in [ (-1,0), (1,0), (0,-1), (0,1) ]:
                        nx = p[0] + dx
                        ny = p[1] + dy
                        # ensure our first point is always the lowest of first column
                        if nx < 0  or  (nx == 0 and ny < 0):
                                continue
                        if not (nx,ny) in points and not (nx,ny) in positions:
                                        positions += [ (nx,ny) ]
        return positions

def removeDoubles(pointsList):
        map(lambda x:x.sort(), pointsList)
        pointsList.sort()
        i = 1 
        while i < len(pointsList):
                if pointsList[i] == pointsList[i-1]:
                        pointsList.pop(i)
                else:
                        i += 1

# adds <howMany> blocks to a list of points
def addBlocks(points, howMany):
        if howMany == 0:
                return [ points ]
        r = []
        for p in getAvailablePositions(points):
                r += addBlocks(points + [p], howMany - 1)
        removeDoubles(r)
        return r

def symetry(points):
        return map(lambda t:(-t[0],t[1]), points)
def rot(points):
        return map(lambda t:(-t[0],-t[1]), points)
def rotL(points):
        return map(lambda t:(-t[1],t[0]), points)
def rotR(points):
        return map(lambda t:(t[1],-t[0]), points)

# moves lowest left point to (0,0)
def center(points):
        minX = min([t[0] for t in points])
        minY = min([t[1] for t in points if t[0] == minX])
        return map(lambda t:(t[0]-minX, t[1]-minY), points)

# returns different symetries and rotations
def transforms(points):
        ret = [points]
        sym = symetry(points)
        for t in [ rotL(points), rotR(points), rot(points), sym, rotL(sym), rotR(sym), rot(sym) ]:
                t = center(t)
                t.sort()
                if not t in ret:
                        ret += [t] 
        return ret[1:]


polyominoes = addBlocks([(0,0)], 9)

# removing identical polyominoes after transformation
i = 0
while i < len(polyominoes):
        for p in transforms(polyominoes[i]):
                polyominoes.remove(p)
        i += 1

print len(polyominoes)

Steven Zheng
Aug 22, 2014

I'm not sure how to do this using computers but it is done before: Polyomino . Look at the column "free"

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...