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.
Matrix
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.
Example:
N = 17600
binary representation: 0100010011000000
matrix: [ [ 0, 1, 0, 0 ],
[ 0, 1, 0, 0 ],
[ 1, 1, 0, 0 ],
[ 0, 0, 0, 0 ] ]
Tetromino shapes
Base shapes
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:
Don't wrap!
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!
Test cases
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 . func3
in JS :P \$\endgroup\$0
, i.e.1111011110111101111
for65535
? \$\endgroup\$15,240,3840,4369,8738,17476,34952,61440
J:71,113,142,226,275,550,802,1100,1136,1604,1808,2272,3208,3616,4400,8800,12832,17600,18176,25664,28928,36352,51328,57856
L:23,46,116,232,368,547,736,785,1094,1570,1856,2188,3140,3712,5888,8752,11776,12560,17504,25120,29696,35008,50240,59392
O:51,102,204,816,1632,3264,13056,26112,52224
S:54,108,561,864,1122,1728,2244,8976,13824,17952,27648,35904
T:39,78,114,228,305,562,610,624,1124,1220,1248,1824,2248,3648,4880,8992,9760,9984,17984,19520,19968,29184,35968,58368
Z:99,198,306,612,1224,1584,3168,4896,9792,19584,25344,50688
\$\endgroup\$