3 ms·
Best way of finding if there are rectangles: > We encode the rows of the grid in a set of bit vectors–four vectors for each row, representing the four possible
by experiment0 15y ago
Best way of finding if there are rectangles:
> We encode the rows of the grid in a set of bit vectors–four vectors for each row, representing the four possible colors. For example, the red vector for a row has a 1 at each position where the corresponding node is red, and zeroes elsewhere. The blue vector has 1s for blue nodes, and so forth. Now we can detect a rectangle merely by taking the logical AND of two rows (an operation that could be a single machine instruction). A rectangle exists if and only if at least two bits are set in the resulting vector.
-- http://bit-player.org/2009/the-17x17-challenge http://bit-player.org/2009/the-17x17-challenge
Thats some lovely hacking.