Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate a list of all Tetrominos?

How can I generate a list of all Tetrominos? Or, more generally, how can I generate a subset of the polyominoes restricted to a number of cells?

like image 424
Mark Avatar asked Oct 19 '25 12:10

Mark


2 Answers

There are many ways to do this. One option that I've found works well is to think about it recursively and more generally. In particular:

  1. A single rectangle is a 1-omino.
  2. For any n-omino, you can create an (n+1)-omino by putting a block adjacent to any of the blocks from an n-omino.

This gives you a recursive way of listing all possible n-ominos. You need to be careful, though, since this will generate multiple rotations and translations of the same n-ominos. You can fix this by picking some reference coordinate system and then translating the n-omino so that it is always flush with the axes of that system. Once you've got that working, you can generate all rotations by just rotating the resulting n-omino around the axes, then translating it back to the canonical position.

like image 107
templatetypedef Avatar answered Oct 21 '25 13:10

templatetypedef


The biggest grid you need for an N-omino is NxN. Generate all then exclude rotations and translations.

You can think of it as a path-following algorithm in N-1 steps. If you start from the top-left cell of the grid and only move right or down from there, you will avoid most translations and rotations. If I'm not mistaken, the only ones that will be left are the isomorphic N-ominones. E.G. the tetromino made by the path Right-Down-Left is the same as Down-Right-Up.

like image 40
kaoD Avatar answered Oct 21 '25 14:10

kaoD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!