By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. This could be generalized into: How to efficiently hash an arbitrary collection of 2D integer coordinates, where a set contains unique pairs of non-negative integers, and a set is considered unique if and only if no translation, rotation, or flip can map it identically to another set?

For impatient readers, please note I'm fully aware of a brute force approach. I'm looking for a better way -- or a very convincing proof that no other way can exist. I'm working on some different algorithms to generate random polyominos.

I want to test their output to determine how random they are -- i. Visually, it is very easy to identify different orientations of a free polyomino, for example the following Wikipedia illustration shows all 8 orientations of the "F" pentomino Source :.

How would one put a number on this polyomino - that is, hash a free polyomino? I don't want to depend on a prepolulated list of "named" polyominos. Broadly agreed-upon names only exists for orders 4 and 5, anyway. This is not necessarily equavalent to enumerating all free or one-sided, or fixed polyominos of a given order. I only want to count the number of times a given configuration appears. If a generating algorithm never produces a certain polyomino it will simply not be counted.

### Subscribe to RSS

What I'm looking for is an efficient PolyHash algorithm. The input polyominos are simply defined as a set of coordinates. One orientation of the T tetronimo could be, for example:. You can assume that that input polyomino will already be normalized to be aligned against the X and Y axes and have only positive coordinates.

Formally, each set:. I'm really looking for novel algorithms that avoid the increasing number of integer operations required by a general brute force approach, described below. This results in a total of 23 set operations for each input set to get the "free" hash:.

Well, I came up with a completely different approach. Also thanks to corsiKa for some helpful insights! The path consists of a sequence of 'turns' including no turn to perform before drawing each unit segment. I think an algorithm for getting the path from the coordinates of the squares is outside the scope of this question.

This does something very important: it destroys all location and orientation information, which we don't need. It is also very easy to get the path of the flipped object: you do so by simply reversing the order of the elements.

Storage is compact because each element requires only 2 bits. It does introduce one additional constraint: the polyomino must not have fully enclosed holes.I became a bit obsessed with Sudokuand soon wanted to write my own Sudoku solver actually I wanted to write my own Sudoku game. But after seeing a lot of pictures of polyomino puzzles, my interest in writing a Sudoku solver deviated to a polyomino puzzle solver.

I thought that filling a board with polygons of diferent shapes and colors seemed a bit more interesting than filling a board with numbers. A polyomino is a collection of cells equal-sized squares which are connectedthat is, each cell shares a border with another one. Looks like attaching a Greek prefix was fancier. For example, the seven Tetris pieces are one-sided tetrominoes, because the S and J tetrominoes are flipped to get the Z and L, respectivelyâ€¦.

Pentomino 5-cell polyomino puzzles were more common than I thought. As far as I know, they are mentioned in Arthur C. The objective is to tile a set of pentominoes on a rectangular board without leaving any blank space.

After reading a bit on the subject, I decided to write a pentomino puzzle solver. There were different ways to solve this problem, but I started with the simplest one. The basic idea of this simple method is as follows:. Given a list of polyominoes of order nwe add a square to each one of them, in each possible position, and we remove any duplicates.

In the following pictures, you can see how all polyominoes of order 3 are generated:.

**Triomino Tiling**

First, the algorithm starts with a monomino. For each position adjacent to it, it adds a square. The final step is to check that there are no duplicates, i.

There are two equal dominoes, so it discards them. Now it starts doing the same thing it did for the monomino, but this time for each of the two dominoes. You can see from the picture that the second domino only bears one new trinomino, because almost all of them are duplicates.I've implemented a set of backtrack algorithms to find solutions to various polyomino and polycube puzzles 2-D and 3-D puzzles where you have to fit pieces composed of little squares or cubes into a confined space.

My approach to the problem is perhaps unusual in that I've implemented many different algorithmic techniques simultaneously into a single puzzle solving software application. I've found that the best algorithm to use for a problem can depend on the size, and dimensionality of the puzzle. To take advantage of this, when the number of remaining pieces reaches configurable transition thresholds my software can turn off one algorithm and turn on another.

DLX is most commonly used with an ordering heuristic that picks the hole or piece with fewest fit choices; but other simple ordering heuristics are shown to improve performance for some puzzles.

In addition to these three core algorithms, a set of constraints are woven into the algorithms giving great performance benefits. These include constraints on the volumes of isolated subspaces, parity or coloring constraints, fit constraints, and constraints to take advantage of rotational symmetries.

In this rather long blog entry I present the algorithms and techniques I've implemented and share my insights into where each works well, and where they don't. You can also download my software source, an executable version of the solver, and the solutions to various well known puzzles.

My original impetus for writing this software was an annoyingly difficult little puzzle called the Tetris Cube.

Each piece has a shape you could make yourself by sticking together little cubes of fixed size. You would need 64 cubes to make them all and accordingly, the puzzle box measures 4x4x4 â€” just big enough to hold them all.

This is an example of a polycube puzzle: a 3-D puzzle where all the pieces are formed from little cubes. We'll also be looking at polyomino puzzles: 2-D puzzles where all the pieces are formed from little squares. The appeal of the Tetris Cube to me is three-fold. First, it's intriguing and surprising to most folks that a puzzle with only twelve pieces could be so wicked hard.

I had spent much time in my youth looking for solutions to the far simpler but still quite challenging two-dimensional Pentominoes puzzle, so when I first saw the Tetris Cube in a gaming store about three years ago, I knew that with the introduction of the third dimension that the Tetris Cube was an abomination straight from Hell. I had to buy it. Since then I've spent many an hour trying to solve it, but I've never found even one of its nearly 10, solutions manually.

Second, I enjoy the challenge of visualizing ways of fitting the remaining pieces into the spaces I have left, and enjoy the logic you can apply to identify doomed partial assemblies. Third, I think working any such puzzle provides a certain amount of tactile pleasure.

I should really buy the wooden version of this thing. But alas, I think that short of having an Einstein-like parietal lobe mutation, you will need both persistence and a fair amount of luck to find even one solution.

If I ever found a solution, I think I'd feel not so much proud as lucky; or maybe just embarrassed that I wasted all that time looking for the solution. In this sense, I think perhaps the puzzle is flawed.

## Subscribe to RSS

But for those of you up for a serious challenge, you should really go buy the cursed thing! But do yourself a favor and make a sketch of the initial solution and keep it in the box so you can put it away as needed. Having some modest programming skill, I decided to kick the proverbial butt of this vexing puzzle back into the fiery chasm from whence it came. My initial program, written in Januarymade use of only my own algorithmic ideas.

But during my debugging, I came across Scott Kurowski's web page describing the software he wrote to solve this very same puzzle. I really enjoyed the page and it motivated me to share my own puzzle solving algorithm and also to read up on the techniques others have devised for solving these types of puzzles. In my zeal to make the software run as fast as possible, over the next couple of weeks I incorporated several of these techniques as well as a few more of my own ideas.

But DLX caused me two problems: first it used a radically different data model and would not be at all easy to add to my existing software; second it was so elegant, I questioned whether there was any real value in the continued pursuit of this pet project. Still I wasn't sure how DLX would compare to and possibly work together with the other approaches I had implemented.

The following November, curiosity finally got the better of me and I began to lie awake at night thinking about how to to integrate DLX into my polycube solver software application.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

This could be generalized into: How to efficiently hash an arbitrary collection of 2D integer coordinates, where a set contains unique pairs of non-negative integers, and a set is considered unique if and only if no translation, rotation, or flip can map it identically to another set? For impatient readers, please note I'm fully aware of a brute force approach. I'm looking for a better way -- or a very convincing proof that no other way can exist.

I'm working on some different algorithms to generate random polyominos. I want to test their output to determine how random they are -- i. Visually, it is very easy to identify different orientations of a free polyomino, for example the following Wikipedia illustration shows all 8 orientations of the "F" pentomino Source :. How would one put a number on this polyomino - that is, hash a free polyomino? I don't want to depend on a prepolulated list of "named" polyominos.

Broadly agreed-upon names only exists for orders 4 and 5, anyway. This is not necessarily equavalent to enumerating all free or one-sided, or fixed polyominos of a given order.

### Polyominoes

I only want to count the number of times a given configuration appears. If a generating algorithm never produces a certain polyomino it will simply not be counted. What I'm looking for is an efficient PolyHash algorithm.

The input polyominos are simply defined as a set of coordinates. One orientation of the T tetronimo could be, for example:. You can assume that that input polyomino will already be normalized to be aligned against the X and Y axes and have only positive coordinates. Formally, each set:. I'm really looking for novel algorithms that avoid the increasing number of integer operations required by a general brute force approach, described below.

This results in a total of 23 set operations for each input set to get the "free" hash:. Well, I came up with a completely different approach. Also thanks to corsiKa for some helpful insights! The path consists of a sequence of 'turns' including no turn to perform before drawing each unit segment. I think an algorithm for getting the path from the coordinates of the squares is outside the scope of this question. This does something very important: it destroys all location and orientation information, which we don't need.

It is also very easy to get the path of the flipped object: you do so by simply reversing the order of the elements. Storage is compact because each element requires only 2 bits.

It does introduce one additional constraint: the polyomino must not have fully enclosed holes. Formally, it must be simply connected. Most discussions of polyominos consider a hole to exist even if it is sealed only by two touching corners, as this prevents tiling with any other non-trivial polyomino.

Tracing the edges is not hindered by touching corners as in the single heptomino with a holebut it cannot leap from one outer loop to an inner one as in the complete ring-shaped octomino:. It also produces one additional challenge: finding the minumum ordering of the encoded path loop. This is because any rotation of the path in the sense of string rotation is a valid encoding.A polyomino is a geometric figure consisting of one or more equally-sized squares, connected edge to edge.

The number of unique polyominos for a given number of squares is based on the rules at which they're constructed:. Polyominos are used in recreational mathematics, such as trying to compose a large shape from a given set of polyominos. These can be solved using methods similar to the Exact Cover problem, solvable using algorithms such as Kunth's Algorithm X.

Sign In Don't have an account? All 18 pentominos A polyomino is a geometric figure consisting of one or more equally-sized squares, connected edge to edge. The number of unique polyominos for a given number of squares is based on the rules at which they're constructed: Free polyominos may be translated, rotated, reflected. One-side polyominos may be translated or rotated. Fixed polyominos may only be translated. Polyominos of size 7 or higher may have "holes", which may be included or excluded on a given count.

Polyomino puzzles Polyominos are used in recreational mathematics, such as trying to compose a large shape from a given set of polyominos. This article is a stub. You can help Math Wiki by expanding it. Categories :.In some contexts the definition of a polyomino is relaxed. Sometimes polyominoes are generalised to three or more dimensions by aggregating cubes or hypercubes. For some applications mirror image forms are treated as distinct.

Polyominoes composed of seven or more squares may contain holes ie regions which are not tiled with squares but which are unconnected to the exterior of the polyomino. Polyominoes have been used in popular puzzles since the late 19th century, but were first studied systematically by Solomon W. Golomb and were popularized by Martin Gardner. Related to polyominoes are polyiamonds formed from equilateral triangles and polyhexes formed from regular hexagons.

The polyominoes of area n can be found by inductive exhaustive search. For each vacant cell in that square that is adjacent to at least one occupied cell, fill the cell and strike out a bounding row of vacant cells and a bounding column of vacant cells. Symmetry can be accounted for by noting that the group of symmetries of a square has eight elements and is generated by alternating reflections about the x -axis and about a diagonal.

This procedure can be applied repeatedly starting from the monomino to reach any desired area of polyomino, but this becomes computationally expensive for large areas. For example finding all the dodecominoes using this algorithm consumes nearly 90 seconds of CPU time on a 1GHz pentium.

Polyomino A polyomino is a polyform with the square as its base form. It is constructed by placing a number of identical squares in distinct locations on the plane in such a way that at least one edge of each square coincides with an edge of one of the remaining squares, and all squares are simply connected.

If the corner of any square touches the edge of another square at any place other than a corner, the result is not a polyomino. For each strictly positive natural numbernthere are a fixed number of distinct such arrangements of the n squares.

For this purpose, a reflected form of a polyomino is not usually regarded as distinct from the original. The numbers of configurations for small polyominos are listed below. No formula for finding the exact number of polyominoes with n squares has been found.

An Algorithm for Enumerating all n -ominoes polyominoes of n squares The polyominoes of area n can be found by inductive exhaustive search.

See also: tiling External links Karl Dahlke's polyomino finite-rectangle tilings Enumeration of polyominoes.Over eight years ago I created the Polyomino Tiler a browser application that attempts to tile arbitrary grids with sets of polyominoesbut I haven't ever written about the algorithm it uses. If any aspects of what follows are confusing, it may help to play with the polyomino tiler a bit to get a better idea for what it's doing.

So the algorithm needs to be generic enough to not get bogged down in all the edge cases resulting from these two facts. The main preprocessing step is to calculate all possible placements of all available pieces. When hundreds of piece variants are available this step can be lengthy, and the result can require a lot of memory. But the result is essentially a bipartite graph or, in database terms, a many-to-many relationship between placements and grid points. Notice that all of the geometric details have been abstracted away; this means that the rest of the algorithm could just as easily be applied to grids of triangles, or hexagons, or hyperbolic grids, or higher dimensions.

Given the bipartite graph, the problem of tiling the grid can be reformulated as the problem of finding a subset of the placements that, as a whole, is connected to every one of the grid points exactly one time. The search algorithm is a backtracking algorithm that at each step chooses an untiled grid point and a random placement associated with that grid point; it adds that placement to the solution set and then tries to tile the remainder of the grid taking note of which placements are invalidated by the one selected.

If it fails to tile the rest of the grid, then it tries the next placement. If it runs out of placements, then the grid must be untileable. For example, if we decide to start tiling the above grid from grid point A, the search tree might look like this:. The reason the tree is so sparse is that each time we descend we remove placements from the graph that conflict with the one chosen.

Since every placement we select makes several other placements impossible, it's easy to get to a point where there is some grid point that no longer has any possible placements. This is the most common sign of untileability, and it means we need to backtrack and try something different.

For example, if we descended down the ACD branch of the search tree, the graph would look like this, and the existence of grid points with no placements indicates that there's no solution.

A given set of polyominoes places restrictions on what grids can be tiled purely based on their size. This is solely a function of the set of distinct sizes of the polyominoes.

For example, with the tetrominoes, only grids whose size is a multiple of four can be tiled. If the polyominoes have sizes 4 and 6, then only grids whose size is an even number greater than two can be tiled.