Given an unsigned 16-bit integer N, your task is to determine whether its binary representation mapped inside a 4x4 matrix is matching a tetromino shape, and if so, which shape it is.
Each bit of N is mapped inside a 4x4 matrix, from left to right and from top to bottom, starting with the most significant one.
N = 17600 binary representation: 0100010011000000 matrix: [ [ 0, 1, 0, 0 ], [ 0, 1, 0, 0 ], [ 1, 1, 0, 0 ], [ 0, 0, 0, 0 ] ]
There are 7 tetromino shapes, identified by the letters O, I, S, Z, L, J and T:
Rotations and translations
If a shape is translated and/or rotated within the 4x4 matrix, it is still considered a valid variation of the same tetromino. For instance, 17600, 1136, 2272 and 1604 should all be identified as J tetrominoes:
However, the shapes can't wrap around or be shifted beyond any boundary of the matrix. For instance, neither 568 nor 688 should be identified as J tetrominoes (let alone any other shape):
Clarifications and rules
- You may take input as an integer, or directly as 16 binary digits in any reasonable format, such as a 2D array, a flat array or a delimited string.
- The input is guaranteed to be an unsigned 16-bit integer (or its equivalent representation as an array or a string).
- When a valid shape is identified, you must print or return the letter identifying the shape, in either lower or upper case.
- If no shape is identified, you must print or return a value that doesn't match any tetromino letter. You may also choose to return nothing at all.
- To be considered valid, the matrix must contain the exact tetromino shape without any additional cells (see 1911 and 34953 in the test cases).
- This is code-golf, so the shortest answer in bytes wins!
You can follow this link to get the test cases as 2D arrays.
0 -> false 50 -> false 51 -> 'O' 1911 -> false 15 -> 'I' 34952 -> 'I' 34953 -> false 1122 -> 'S' 3168 -> 'Z' 785 -> 'L' 1136 -> 'J' 568 -> false 688 -> false 35968 -> 'T' 19520 -> 'T'
func1 . func2 . func3in JS :P \$\endgroup\$