Consider the following 9 "row patterns", using 0s to represent empty cells and 1s to represent a full cell. Each pattern is associated with an integer \$n\$, such that \$0 \le n \le 8\$ (multiple [1,1,1,1,1,1]
s exist as there's some difference that we don't care about):
\$n\$ | Pattern |
---|---|
0 | [0,0,0,0,0,0] |
1 | [1,1,1,1,1,1] |
2 | [1,1,1,1,1,1] [1] |
3 | [1,1,1,1,1,1] [1] |
4 | [1,1,0,1,1,1] |
5 | [0,1,1,0,1,0] |
6 | [1,0,0,1,0,1] |
7 | [0,1,0,0,0,0] |
8 | [0,0,0,0,1,0] |
Given 6 integers, each of which is between \$0\$ and \$8\$ inclusive, we can use these rows to build a 6x6 square matrix. For example, consider an input of [1,4,6,6,0,0]
. We'll start with 1
being the bottom row and the 0
s being the top 2, giving:
[0,0,0,0,0,0]
[0,0,0,0,0,0]
[1,0,0,1,0,1]
[1,0,0,1,0,1]
[1,1,0,1,1,1]
[1,1,1,1,1,1]
For each column in this matrix, we can see that every non-zero element has a "support" down to the base, i.e. no 1
has a 0
below it. However, this isn't the case for [2,3,4,5,0,0]
:
[0,0,0,0,0,0]
[0,0,0,0,0,0]
[0,1,1,0,1,0]
[1,1,0,1,1,1]
[1,1,1,1,1,1]
[1,1,1,1,1,1]
As the third column from the left has a 0
below the top 1
, meaning that it is "unsupported".
Given 6 integers between 0
and 8
inclusive, in any reasonable format, you should output a truthy value if, in the matrix represented by these numbers, all non-zero values are supported; and a falsey value if not.
This is code-golf, so the shortest code in bytes wins.
Test cases:
[1,4,6,6,0,0] => valid
[2,1,2,4,7,7] => valid
[5,8,8,0,0,0] => valid
[2,0,2,0,0,0] => invalid
[2,3,4,5,0,0] => invalid
top&=bottom
orbottom|=top
. if the number doesn't change the top row is supported. \$\endgroup\$