Input
An \$m\$ by \$n\$ binary matrix, with \$m\$ and \$n\$ both at least 2.
Think of the ones as gobs of melted cheese, which stretch as we expand the matrix horizontally and vertically.
More precisely...
Output
A \$2m-1\$ by \$2n-1\$ binary matrix, constructed as follows...
First insert rows of zeros between the rows, and insert columns of zeros between the columns. For example, consider the input:
0 1 1
1 0 1
1 0 0
After we insert the zeros:
0 0 1 0 1
0 0 0 0 0
1 0 0 0 1
0 0 0 0 0
1 0 0 0 0
To make it extra clear what we're doing, here is the same matrix with the new zeros visualized as #
:
0 # 1 # 1
# # # # #
1 # 0 # 1
# # # # #
1 # 0 # 0
Now, for each new 0
(or #
in our visualization), if is between two ones (horizontally, vertically, or diagonally), convert it to a 1:
0 # 1 1 1
# 1 # 1 1
1 # 0 # 1
1 # # # #
1 # 0 # 0
Or, exiting our visualization and converting #
back to 0
:
0 0 1 1 1
0 1 0 1 1
1 0 0 0 1
1 0 0 0 0
1 0 0 0 0
And that is the actual, final result you return.
Rules
- This is code golf with standard site rules
- You may take input in any reasonable format (array of arrays, built-in matrix type, single flat list, etc)
- With one exception: you may not take a list of the coordinates of the ones.
- This exception applies to the output as well: you must output all of the zeros and ones in some reasonable form.
- You may optionally take \$m\$ and \$n\$ as a second argument
- You can do I/O using images, so long as there is a 1-1 mapping with the matrix entries.
Brownie Points
- Solution using images for I/O.
- J solution under 47 bytes.
Test Cases
1 0
0 1
->
1 0 0
0 1 0
0 0 1
1 1
0 1
->
1 1 1
0 1 1
0 0 1
1 1
1 1
->
1 1 1
1 1 1
1 1 1
1 1
0 0
->
1 1 1
0 0 0
0 0 0
1 1 0 1 0 1
1 0 0 1 0 0
0 1 0 0 1 0
0 1 0 0 1 1
1 0 1 0 0 0
->
1 1 1 0 0 0 1 0 0 0 1
1 1 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 1 0 0 0 0
0 1 0 0 0 0 0 1 0 0 0
0 0 1 0 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 1 0
0 0 1 0 0 0 0 0 1 1 1
0 1 0 1 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 0 0 0