But Is It Art? is an esolang created by ais523, where one step is break the program into orthogonally connected "tiles":
A BBBB
A B B
AA CC
A CC
Each separate letter shows a different tile. Interestingly, programs in But Is It Art? only rely on the orientations of the tiles themselves, not their placement. This means that the above program is functionally equivalent to
CC A
CC A
BBBB AA
B B A
But this isn't equivalent to
BBB A
B B AA
CC A
CC A
Or to
DDD A
DDD AA
CC ABBBB
CC AB B
You are to take two binary rectangular matrices, \$A\$ and \$B\$. Each matrix will have zero or more "tiles" consisting of 1
s that are orthogonally connected to zero or more other 1
s. You should then output 2 distinctive consistent values that indicate whether the tiles in \$A\$ and \$B\$ are equivalent per But Is It Art?'s definition of equivalent grids.
For example,
A = B =
0000111000 11000011
0110010010 10011100
0100011110 00101001
1011000001 10101111
1000000000
Are equivalent. If you can't see it, try replacing the 1
s with letters, similar to above, to form groups of differently lettered tiles:
A = B =
0000AAA000 BB0000DD
0BB00A00A0 B00AAA00
0B000AAAA0 00C0A00A
C0DD00000E E0C0AAAA
C000000000
You can assume that the matrices will always be rectangular and will only ever contain 1
and 0
. They will never be empty, but are not guaranteed to contain a 1
, or to be the same dimensions.
You may take these matrices as newline separated strings, with a non-digit, non-newline separator between them; 2D nested arrays; a string representation of a matrix; or any reasonable representation of a binary matrix. You may take input as 2 lists of integers converted from binary, representing the rows (so the example A
above would be [56, 402, 286, 705, 512]
)
This is code-golf, so the shortest code in bytes wins
Test cases
A | B | result |
---|---|---|
1101110 |
1111100101 |
false |
0110111 |
110000101 |
true |
11111 |
11111011011 |
true |
010010 |
000000 |
false |
10 |
1 |
true |
1111111110 |
1111111110 |
true |
1000 |
1000 |
false |