Programmed Tetris for play? This also is how packaging bricks stacking process to be more stable palletized, then more so once shrink wrapped. There are programs that analyze carton size into a 'cube' for squeeze fork lifts.