the left and right arguments would likelook like this (boxed for clarity):
the left and right arguments would like like this (boxed for clarity):
the left and right arguments would look like this (boxed for clarity):
J, 90 87 85 78 7374 bytes
((#@~."1@|:e.1~1,#)@#~*/@,&,[:g+/@])(,:&(-/~)0j1&*)(g=.+./ .*^:_~)"[email protected]:@1 Find all horizontally connected pieces. To do this, we create an adjacency matrix of all the positions, where adjacency is defined by the distance between two elements being in the set
_1 0 1:0 0j1 0j2 1j1 2j1 +----------------------- 0 |1 1 0 0 0 0j1 |1 1 1 0 0 0j2 |0 1 1 0 0 1j1 |0 0 0 1 0 2j1 |0 0 0 0 1And then take the transitive closure of that matrix "or-multiplied" by itself until a fixed point. The result shows all the horizontal connections:
1 1 1 0 0 <- 0 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j1 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j2 is connected to 0, 0j1, 0j2 0 0 0 1 0 <- 1j1 is only connected to itself 0 0 0 0 1 <- 2j1 is only connected to itselfFind all vertically connected pieces. To do this, we reuse the logic in step 1, by first multiplying every position by
0j1, which has the effect of rotating the entire board 45 degress left. Now vertical connections will be horizontal ones. The resulting final matrix this time is:1 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1Next, we use the rows from the previous steps as masks to define the groups of pieces we need to validate:
┌──┬──┬──┬──┬──┐ │rc│gc│bc│gc│gc│ <- Vertically connected pieces │ │gs│ │gs│gs│ │ │gf│ │gf│gf│ ├──┼──┼──┼──┼──┤ │rc│rc│rc│gs│gf│ <- Horizontally connected pieces │gc│gc│gc│ │ │ │bc│bc│bc│ │ │ └──┴──┴──┴──┴──┘For each group, we validate that one property is all the same, and that the other property is all different. This part should have been easier to golf but the best approach I came up with was
(#@~."1@|:e.1~1,#). This takes the transpose of the input:ggg csfand takes the length of the uniq of each row, giving:
1 3. We then check if both of these are elments of "1catted with the inputand "input length" are members of that list.Finally, we check that all elements are connected. Here we use our adjacency matrix trick a third time, except now adjacency is defined as a horizontal or vertical connection:
1 1 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 1and we check that its transitive closure becomes the matrix consisting of all ones:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
J, 90 87 85 78 73 bytes
((#@~."1@|:e.1,#)@#~*/@,&,[:g+/@])(,:&(-/~)0j1&*)(g=.+./ .*^:_~)"[email protected]:@1 Find all horizontally connected pieces. To do this, we create an adjacency matrix of all the positions, where adjacency is defined by the distance between two elements being in the set
_1 0 1:0 0j1 0j2 1j1 2j1 +----------------------- 0 |1 1 0 0 0 0j1 |1 1 1 0 0 0j2 |0 1 1 0 0 1j1 |0 0 0 1 0 2j1 |0 0 0 0 1And then take the transitive closure of that matrix "or-multiplied" by itself until a fixed point. The result shows all the horizontal connections:
1 1 1 0 0 <- 0 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j1 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j2 is connected to 0, 0j1, 0j2 0 0 0 1 0 <- 1j1 is only connected to itself 0 0 0 0 1 <- 2j1 is only connected to itselfFind all vertically connected pieces. To do this, we reuse the logic in step 1, by first multiplying every position by
0j1, which has the effect of rotating the entire board 45 degress left. Now vertical connections will be horizontal ones. The resulting final matrix this time is:1 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1Next, we use the rows from the previous steps as masks to define the groups of pieces we need to validate:
┌──┬──┬──┬──┬──┐ │rc│gc│bc│gc│gc│ <- Vertically connected pieces │ │gs│ │gs│gs│ │ │gf│ │gf│gf│ ├──┼──┼──┼──┼──┤ │rc│rc│rc│gs│gf│ <- Horizontally connected pieces │gc│gc│gc│ │ │ │bc│bc│bc│ │ │ └──┴──┴──┴──┴──┘For each group, we validate that one property is all the same, and that the other property is all different. This part should have been easier to golf but the best approach I came up with was
(#@~."1@|:e.1,#). This takes the transpose of the input:ggg csfand takes the length of the uniq of each row, giving:
1 3. We then check if both of these are elments of "1catted with the input length".Finally, we check that all elements are connected. Here we use our adjacency matrix trick a third time, except now adjacency is defined as a horizontal or vertical connection:
1 1 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 1and we check that its transitive closure becomes the matrix consisting of all ones:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
J, 90 87 85 78 74 bytes
((#@~."1@|:e.~1,#)@#~*/@,&,[:g+/@])(,:&(-/~)0j1&*)(g=.+./ .*^:_~)"[email protected]:@1 Find all horizontally connected pieces. To do this, we create an adjacency matrix of all the positions, where adjacency is defined by the distance between two elements being in the set
_1 0 1:0 0j1 0j2 1j1 2j1 +----------------------- 0 |1 1 0 0 0 0j1 |1 1 1 0 0 0j2 |0 1 1 0 0 1j1 |0 0 0 1 0 2j1 |0 0 0 0 1And then take the transitive closure of that matrix "or-multiplied" by itself until a fixed point. The result shows all the horizontal connections:
1 1 1 0 0 <- 0 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j1 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j2 is connected to 0, 0j1, 0j2 0 0 0 1 0 <- 1j1 is only connected to itself 0 0 0 0 1 <- 2j1 is only connected to itselfFind all vertically connected pieces. To do this, we reuse the logic in step 1, by first multiplying every position by
0j1, which has the effect of rotating the entire board 45 degress left. Now vertical connections will be horizontal ones. The resulting final matrix this time is:1 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1Next, we use the rows from the previous steps as masks to define the groups of pieces we need to validate:
┌──┬──┬──┬──┬──┐ │rc│gc│bc│gc│gc│ <- Vertically connected pieces │ │gs│ │gs│gs│ │ │gf│ │gf│gf│ ├──┼──┼──┼──┼──┤ │rc│rc│rc│gs│gf│ <- Horizontally connected pieces │gc│gc│gc│ │ │ │bc│bc│bc│ │ │ └──┴──┴──┴──┴──┘For each group, we validate that one property is all the same, and that the other property is all different. This part should have been easier to golf but the best approach I came up with was
(#@~."1@|:e.~1,#). This takes the transpose of the input:ggg csfand takes the length of the uniq of each row, giving:
1 3. We then check if both1and "input length" are members of that list.Finally, we check that all elements are connected. Here we use our adjacency matrix trick a third time, except now adjacency is defined as a horizontal or vertical connection:
1 1 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 1and we check that its transitive closure becomes the matrix consisting of all ones:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
J, 90 87 85 78 7873 bytes
((|:-:&([#@~."1@|:+/="1)e.1,:#\#)@#~*/@,&,[:g+/@])(,:&(-/~)0j1&*)(g=.+./ .*^:_~)"[email protected]:@1 Find all horizontally connected pieces. To do this, we create an adjacency matrix of all the positions, where adjacency is defined by the distance between two elements being in the set
_1 0 1:0 0j1 0j2 1j1 2j1 +----------------------- 0 |1 1 0 0 0 0j1 |1 1 1 0 0 0j2 |0 1 1 0 0 1j1 |0 0 0 1 0 2j1 |0 0 0 0 1And then take the transitive closure of that matrix "or-multiplied" by itself until a fixed point. The result shows all the horizontal connections:
1 1 1 0 0 <- 0 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j1 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j2 is connected to 0, 0j1, 0j2 0 0 0 1 0 <- 1j1 is only connected to itself 0 0 0 0 1 <- 2j1 is only connected to itselfFind all vertically connected pieces. To do this, we reuse the logic in step 1, by first multiplying every position by
0j1, which has the effect of rotating the entire board 45 degress left. Now vertical connections will be horizontal ones. The resulting final matrix this time is:1 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1Next, we use the rows from the previous steps as masks to define the groups of pieces we need to validate:
┌──┬──┬──┬──┬──┐ │rc│gc│bc│gc│gc│ <- Vertically connected pieces │ │gs│ │gs│gs│ │ │gf│ │gf│gf│ ├──┼──┼──┼──┼──┤ │rc│rc│rc│gs│gf│ <- Horizontally connected pieces │gc│gc│gc│ │ │ │bc│bc│bc│ │ │ └──┴──┴──┴──┴──┘For each group, we validate that one property is all the same, and that the other property is all different. This part should have been easier to golf but the best approach I came up with was
(|:-:&([#@~."1@|:+/="1)e.1,:#\#). This first creates a matrix like:1 1 1 1 2 3and compares it totakes the transpose of the input:
ggg csf"under"and takes the "self-classify"length of the uniq of each row, giving:
1 3. What does this mean?1 1 1 <- the self classify of 1 1 1 0 0 0 0 0 0 1 0 0 <- the self classify of 0 1 2 0 1 0 which is just the identity matrix 0 0 1Finally we add We then check if both of these two together elementwise:
2 1 1 0 1 0 0 0 1The transposeare elments of "
1catted with the input will have this same "signature" iff it has the properties we needlength".Finally, we check that all elements are connected. Here we use our adjacency matrix trick a third time, except now adjacency is defined as a horizontal or vertical connection:
1 1 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 1and we check that its transitive closure becomes the matrix consisting of all ones:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
J, 90 87 85 78 bytes
((|:-:&([:+/="1)1,:#\)@#~*/@,&,[:g+/@])(,:&(-/~)0j1&*)(g=.+./ .*^:_~)"[email protected]:@1 Find all horizontally connected pieces. To do this, we create an adjacency matrix of all the positions, where adjacency is defined by the distance between two elements being in the set
_1 0 1:0 0j1 0j2 1j1 2j1 +----------------------- 0 |1 1 0 0 0 0j1 |1 1 1 0 0 0j2 |0 1 1 0 0 1j1 |0 0 0 1 0 2j1 |0 0 0 0 1And then take the transitive closure of that matrix "or-multiplied" by itself until a fixed point. The result shows all the horizontal connections:
1 1 1 0 0 <- 0 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j1 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j2 is connected to 0, 0j1, 0j2 0 0 0 1 0 <- 1j1 is only connected to itself 0 0 0 0 1 <- 2j1 is only connected to itselfFind all vertically connected pieces. To do this, we reuse the logic in step 1, by first multiplying every position by
0j1, which has the effect of rotating the entire board 45 degress left. Now vertical connections will be horizontal ones. The resulting final matrix this time is:1 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1Next, we use the rows from the previous steps as masks to define the groups of pieces we need to validate:
┌──┬──┬──┬──┬──┐ │rc│gc│bc│gc│gc│ <- Vertically connected pieces │ │gs│ │gs│gs│ │ │gf│ │gf│gf│ ├──┼──┼──┼──┼──┤ │rc│rc│rc│gs│gf│ <- Horizontally connected pieces │gc│gc│gc│ │ │ │bc│bc│bc│ │ │ └──┴──┴──┴──┴──┘For each group, we validate that one property is all the same, and that the other property is all different. This part should have been easier to golf but the best approach I came up with was
(|:-:&([:+/="1)1,:#\). This first creates a matrix like:1 1 1 1 2 3and compares it to the transpose of the input:
ggg csf"under" the "self-classify" of each row. What does this mean?
1 1 1 <- the self classify of 1 1 1 0 0 0 0 0 0 1 0 0 <- the self classify of 0 1 2 0 1 0 which is just the identity matrix 0 0 1Finally we add these two together elementwise:
2 1 1 0 1 0 0 0 1The transpose of the input will have this same "signature" iff it has the properties we need.
Finally, we check that all elements are connected. Here we use our adjacency matrix trick a third time, except now adjacency is defined as a horizontal or vertical connection:
1 1 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 1and we check that its transitive closure becomes the matrix consisting of all ones:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
J, 90 87 85 78 73 bytes
((#@~."1@|:e.1,#)@#~*/@,&,[:g+/@])(,:&(-/~)0j1&*)(g=.+./ .*^:_~)"[email protected]:@1 Find all horizontally connected pieces. To do this, we create an adjacency matrix of all the positions, where adjacency is defined by the distance between two elements being in the set
_1 0 1:0 0j1 0j2 1j1 2j1 +----------------------- 0 |1 1 0 0 0 0j1 |1 1 1 0 0 0j2 |0 1 1 0 0 1j1 |0 0 0 1 0 2j1 |0 0 0 0 1And then take the transitive closure of that matrix "or-multiplied" by itself until a fixed point. The result shows all the horizontal connections:
1 1 1 0 0 <- 0 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j1 is connected to 0, 0j1, 0j2 1 1 1 0 0 <- 0j2 is connected to 0, 0j1, 0j2 0 0 0 1 0 <- 1j1 is only connected to itself 0 0 0 0 1 <- 2j1 is only connected to itselfFind all vertically connected pieces. To do this, we reuse the logic in step 1, by first multiplying every position by
0j1, which has the effect of rotating the entire board 45 degress left. Now vertical connections will be horizontal ones. The resulting final matrix this time is:1 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1Next, we use the rows from the previous steps as masks to define the groups of pieces we need to validate:
┌──┬──┬──┬──┬──┐ │rc│gc│bc│gc│gc│ <- Vertically connected pieces │ │gs│ │gs│gs│ │ │gf│ │gf│gf│ ├──┼──┼──┼──┼──┤ │rc│rc│rc│gs│gf│ <- Horizontally connected pieces │gc│gc│gc│ │ │ │bc│bc│bc│ │ │ └──┴──┴──┴──┴──┘For each group, we validate that one property is all the same, and that the other property is all different. This part should have been easier to golf but the best approach I came up with was
(#@~."1@|:e.1,#). This takes the transpose of the input:ggg csfand takes the length of the uniq of each row, giving:
1 3. We then check if both of these are elments of "1catted with the input length".Finally, we check that all elements are connected. Here we use our adjacency matrix trick a third time, except now adjacency is defined as a horizontal or vertical connection:
1 1 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 0 0 1 1and we check that its transitive closure becomes the matrix consisting of all ones:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1