Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 1447 characters in body
Source Link
Jonah
  • 34.1k
  • 4
  • 41
  • 95

J, 114 bytes

-.@(-:g)#,=&#[:~.@;@,(g=.|.@|:^:2)([:(#~4<#&>)@(</.~[:+./ .*^:_~1>:|@-/~)$j./@#:I.@,)@:="2]|.!.(u:0)~[:>@,@{<@i:@$

Try it online!

The basic approach is the only mildly interesting part, so I will explain that without breaking down the J mechanics, which are straightforward, could likely be golfed further, though it wouldn't be terribly interesting without a high-level strategy change as well.

  1. Do the 180 rotation.
  2. Check where it is equal to the input.
  3. Also check every possible 2d sliding of the input. You can imagine it as two sheets of paper, keeping the edges aligned, sliding the top one in every direction where there is still any overlap.
  4. For each of these, we then have a boolean matrix showing which elements are equal. But we only care about connected 1 islands of length 5 or more.
  5. To find these, we turn the 1s into coordinates and compute an adjacency matrix, taking their transitive closure, grouping by equal rows, and only keeping "sets" of equal rows of length 5 or more. This is part is done here .
  6. We combine all these valid coordinates we've found for every slid position, take their uniq, and see if it has as many elements as the input. If so, we are Mondrian.
  7. Finally, we check if the rotation is equal to the input directly, and filter away our input if it is.

J, 114 bytes

-.@(-:g)#,=&#[:~.@;@,(g=.|.@|:^:2)([:(#~4<#&>)@(</.~[:+./ .*^:_~1>:|@-/~)$j./@#:I.@,)@:="2]|.!.(u:0)~[:>@,@{<@i:@$

Try it online!

J, 114 bytes

-.@(-:g)#,=&#[:~.@;@,(g=.|.@|:^:2)([:(#~4<#&>)@(</.~[:+./ .*^:_~1>:|@-/~)$j./@#:I.@,)@:="2]|.!.(u:0)~[:>@,@{<@i:@$

Try it online!

The basic approach is the only mildly interesting part, so I will explain that without breaking down the J mechanics, which are straightforward, could likely be golfed further, though it wouldn't be terribly interesting without a high-level strategy change as well.

  1. Do the 180 rotation.
  2. Check where it is equal to the input.
  3. Also check every possible 2d sliding of the input. You can imagine it as two sheets of paper, keeping the edges aligned, sliding the top one in every direction where there is still any overlap.
  4. For each of these, we then have a boolean matrix showing which elements are equal. But we only care about connected 1 islands of length 5 or more.
  5. To find these, we turn the 1s into coordinates and compute an adjacency matrix, taking their transitive closure, grouping by equal rows, and only keeping "sets" of equal rows of length 5 or more. This is part is done here .
  6. We combine all these valid coordinates we've found for every slid position, take their uniq, and see if it has as many elements as the input. If so, we are Mondrian.
  7. Finally, we check if the rotation is equal to the input directly, and filter away our input if it is.
Source Link
Jonah
  • 34.1k
  • 4
  • 41
  • 95

J, 114 bytes

-.@(-:g)#,=&#[:~.@;@,(g=.|.@|:^:2)([:(#~4<#&>)@(</.~[:+./ .*^:_~1>:|@-/~)$j./@#:I.@,)@:="2]|.!.(u:0)~[:>@,@{<@i:@$

Try it online!

AltStyle によって変換されたページ (->オリジナル) /