1
1
Idea:
Consider a 2-bit bitmap of arbitrary side-lengths overlaid on a coordinate grid and imaged with random data (1's represent an element of the image, 0's represent the "blank" canvas background):
y x—0 2 4 6 8 10 14 18
|
0 0000000000111100000000
0000000011111110000000
2 0000111111111111000000
0000011111111111000000
4 0000000000000000000000
1111111000000000011111
6 1111111111100000000011
1111111111111111000000
Next, consider how the rasterized image may be described using a series of drawn, solid rectangles. Example:
0 2 4 6 8 101214161820
0 0000000000111100000000
0000000011111110000000
2 0000111111111111000000
0000011111111111000000
4 0000000000000000000000
xxxxxxx000000000011111
6 xxxxxxx111100000000011
xxxxxxx111111111000000
The x's describe a region of the bitmap that may be described using a solid rectangle. Finally, consider how that rectangular section of the image can be described under the X-Y coordinate system by two of its vertices in the format:
{x0,y0,x1,y1}
In this case,
{0,5,6,7}
describes the example rectangular section.
Challenge: Design a program which receives a 2D matrix containing bitmap data and outputs a concatenated list of rectangle coordinates.
Restrictions:
The output, when processed by remapping (plotting using 1's) the rectangles back onto a blank coordinate canvas (a canvas of all 0's) of the same side-length dimensions, should yield exactly the input matrix.
The output should be a concatenated list of all computed rectangles, no extraneous parsing characters or structures distinguishing one set of coordinates from another. The list will be read top-down, ordering will be inferred given that each rectangle requires only two coordinates to be described.
Example I/O:
(Do mind that this example in no way presents the ideal output, however, it is a valid output.)
Input 2D matrix:
0000000000111100000000
0000000011111110000000
0000111111111111000000
0000011111111111000000
0000000000000000000000
1111111000000000011111
1111111111100000000011
1111111111111111000000
Output concatenated list:
{10,0,13,3,8,1,9,3,5,2,7,3,4,2,4,2,14,1,14,3,15,2,15,3,0,5,6,7,7,6,10,7,11,7,15,7,17,5,21,5,20,6,21,6}
Efficiency score:
Programs will be ranked by their average-case efficiency using this resource (or one which functions identically) to generate pseudorandom, 2-bit, 20x20 matrices. Determine the average-case efficiency by calculating the arithmetic mean of the output lengths of at least 10 iterations (sum of the lengths divided by the number of iterations). The lesser the average length of the output, the greater the efficiency.
I have completely redesigned the phrasing and approach of the post based on everyone's input on the original. It is quite literally no longer the same post. If there is any further uncertainty, please inform me (for one thing, I'm not sure about the number of iterations in the average, but 10 seemed like enough). As it stands now, I believe I have covered all previous bases of uncertainty and confusion. – B.fox – 2018-10-14T20:27:20.407
Let us continue this discussion in chat.
– B.fox – 2018-10-15T17:54:44.167There is a missing comma in the example output:
{10,0,13,3,8,19,3,…should be{10,0,13,3,8,1,9,3,…. Also, please edit the question to clarify whether rectangles may overlap. – Anders Kaseorg – 2018-10-18T03:18:29.560@AndersKaseorg Nice find, I'm mystified as to how that comma became missing. For overlapping rectangles, there is no restriction against them so they are allowed. – B.fox – 2018-10-18T11:34:57.287
@AndersKaseorg Oops, appears I eyed my own graph wrong there, thanks. – B.fox – 2018-10-18T23:23:03.983