[Math] How to find the smallest square possible, out of Tetris pieces

algorithms

I need to arrange an uncertain number of Tetris pieces, into the smallest possible square. The pieces I get are static, so I am not allowed to turn them and the square is allowed to have holes inside.

I am supposed to write a program to do this, but I think this is more of a mathematical problem.

In total, there are 19 different possible pieces. I thought of starting to create the minimal square, in case all the pieces fit in perfectly.

The equation would be: $m = \sqrt{n\cdot 4}$ rounded up, with m being the minimal size and n being the number of pieces you have. All the pieces are typical Tetris pieces made out of 4 combined blocks.

My idea now was to try to fit all pieces into this square, and enlarge it by 1 if it doesn't fit. The obvious problem now is the algorithm, to place the pieces in the best way possible. For doing that I only came up with the idea to define certain pieces, which combine to a rectangle together. I the program would find all the pieces needed for this rectangle, it would know how to continue with those pieces.

This would actually work with some examples, but there are also a lot of possible combinations, where the smallest square possible wouldn't even contain one rectangle inside.

If anyone has an idea how to solve this, I'd really appreciate the help.

Edit: I am looking for an algorithm that actually places the pieces in the square.

Best Answer

This is not an answer, just an illustration that the largest square necessary is $9$ x $9$ as it can enclose all $19$ Tetris pieces. Done manually, I'm afraid.

enter image description here