The challenge is about finding an optimal solution on how to place a number of given shapes. It is oriented on the principle of Tetris, where it is optimal to pack the given pieces as tight as possible.
An optimal solution means that all shapes could be placed in one rectangle block filling the width of the playground. If there is no optimal solution possible, the code should find a solution where holes are placed as high as possible (thus allowing to have a subpart of the solution being optimal). Empty spaces on top of the solution are also counted as holes (see example at the bottom).
- There are predefined Tetris shapes:
I J L S Z O T
- There could be multiple shapes of the same type available
- There is a playground with a certain width X
- The minimum width is 4, there is no maximum width
- There is no limitation for the height of the playground
- It is possible to rotate the shapes in 4 directions (Up, Left, Right, Down)
- It is NOT possible to mirror the shapes (Turning L into J or S into Z)
T: T TTT I: IIII J: JJJ J L: L LLL S: SS SS Z: ZZ ZZ O: OO OO
A bit of imagination is needed, but everyone who played Tetris should be familiar with the shapes.
A call to a solution using Python could look like the following:
tetrissolver.py <Width> <Shape1> <Shape2> <ShapeN>
tetrissolver.py 4 S S T T L
The result would be some kind of output which shows the optimal solution (tightest possible packaging). Bonus points if the solution also returns if the found solution is optimal.
Possible output of the above input in a text format:
LLLT LSTT SSST STSS TTTS The found solution is optimal
If there is no optimal solution available, the code should find a solution with the least amount of holes in it. Empty spaces on top of the package are counted as holes. The above example with an additional T element could look like the following in the solution (holes marked with X):
XTXX TTTX LLLT LSTT SSST STSS TTTS The found solution is NOT optimal
The solution should find the most optimal package. Holes should be placed as high as possible. If two solutions generate the same quality of packages (optimal packages if possible, same amount of holes), the smallest solution wins.