I am currently doing a small task to solve problems in C, so here is my problem: I get a console program that receives Tetris elements in standard input, for example,
.
.
.
.
..
....
....
....
.
.
....
etc... (max 26 pieces)
and I have to figure out how to make them fit in the smallest possible square (without rotation) and in the very top left corner in order to deduce the following for the previous example:
ABB.
ABBC
ACCC
A...
(where letters are assigned in order of appearance).
So, I decided that the fastest way for my computer to check whether a piece is suitable in a spot on the map is to perform bitwise execution &. If it gives 0, it fits.
That way I can check if
1100
1100
0000
0000
fit:
1000
1000
1000
1000
if (a & b == 0), , . , , :
b >> 1 =
0110
0110
0000
0000
, , .
, short int (16 ), (, long long, 8x8) 0 :
0110
0110
0000
0000
to
0000
0000
0011
0011
, :
00000000
00110000
00110000
00000000
00000000
00000000
00000000
00000000
64- int 1 0.