You should write a program or function which given a list of tetris blocks as input outputs or returns the biggest gap between two points in the same height level which the pieces can connect.
The 7 types of tetris pieces are the following:
We will refer to these pieces by the letters I, J, L, O, S, T and Z respectively, referring to their shapes. You can rotate the pieces but cannot mirror them just like in a Tetris game.
Our task is to create an orthogonally connected area (sides connected to sides) from the given pieces. This area should connect (also orthogonally) two unit squares which are at the same height. We should find the biggest possible gap between the two squares which we can bridge.
Detailed examples
With the piece L we can connect a gap of 3
L
XLLLX
With the piece S we can connect a gap of 2
SS
XSSX
With the pieces S,S,O we can connect a gap of 7 (Note that we can't connect a gap of 8)
S
XSSOO SSX
SOOSS
Input
- A string representing the available pieces containing only the uppercase letters I, J, L, O, S, T and Z. Every letter represents a complete tetris piece.
- The letters will be in alphabetical order in the string.
- The string will be at least one character long.
Output
- A single positive integer, the biggest gap connectable with the given pieces.
Examples
Input => Output
OSS => 7
LS => 5
LZ => 6
ZZZZ => 10
LLSSS => 14
IIJSSSTTZ => 28
IISSSSSS => 24
OOOSSSSSSSSSSSSTT => 45
IJLOSTZ => 21
IJLOSTZZZZZZZ => 37
IIJLLLOSTT => 31
IJJJOOSSSTTZ => 35
This is code-golf so the shortest entry wins.