9
\$\begingroup\$

Given a positive integer \$n\$, output \$n\$ 2D bool images with the same width and height such that:

  1. Each image should be 4-connected, i.e. for each two pixels that are true, you can start from one and go up, down, left and right for some times to the other pixel, only passing through true pixels.
  2. Each image should have no holes, i.e. the complement should be 4-connected.
  3. If we choose itself or its complement for each image, their intersection should be non-empty and 4-connected.

Examples (only a finite amount of solutions shown, but there are infinitely many more)

Input: 1

Possible output:

.....
.***.
.**..
..*..

Input: 1

Possible output:

.....
...*.
.....
.....

Input: 2

Possible output:

..... .....
.***. ..**.
..... ..**.
..... .....

Input: 2

Possible output:

..... .....
.**.. ..**.
..**. ..**.
..... .....

Input: 3

Possible output:

..... ..... .....
.**.. ..**. .....
.**.. ..**. .***.
..... ..... .***.

Input: 4

Possible output:

....... ....... ....... .......
.***... ..***.. ....... .......
.***... ..***.. .*****. .......
.***... ..***.. .*****. .*****.
.***... ..***.. ....... .*****.
....... ....... ....... .......

The shortest code in each language wins.

Reference

Sandbox

\$\endgroup\$
7
  • \$\begingroup\$ can output be binary matrices? \$\endgroup\$
    – wasif
    Jun 20 '21 at 5:40
  • \$\begingroup\$ @Wasif That's quite reasonable \$\endgroup\$
    – l4m2
    Jun 20 '21 at 5:42
  • 1
    \$\begingroup\$ @AndersKaseorg Fixed. Not sure what happened to my thought that time making a wrong n=4 example. \$\endgroup\$
    – l4m2
    Jun 20 '21 at 10:56
  • 1
    \$\begingroup\$ @Spitemaster Condition 3 already implies that the images must be distinct (if \$A = B\$, then \$A ∩ \bar B ∩ C ∩ D = \varnothing\$), and also that you must choose the width and height to be large enough for the given \$n\$. \$\endgroup\$ Jun 20 '21 at 20:43
  • 1
    \$\begingroup\$ @DominicvanEssen If you take the entire set of all images, then all \$2^N\$ arrangements of taking the image or its complement for each should be valid. As an example, if you have A, B, C, then the intersections of ABC, AB(!C), A(!B)C, A(!B)(!C), (!A)BC, (!A)B(!C), (!A)(!B)C, and (!A)(!B)(!C) all need to be valid. \$\endgroup\$
    – hyper-neutrino
    Jun 20 '21 at 22:55
8
\$\begingroup\$

Python, 62 bytes

lambda n:[[[0,j>>i&1,1]for j in range(1<<n)]for i in range(n)]

Try it online!

Generates \$3 × 2^n\$ images like these:

..*  ..*  ..*  ..*
.**  ..*  ..*  ..*
..*  .**  ..*  ..*
.**  .**  ..*  ..*
..*  ..*  .**  ..*
.**  ..*  .**  ..*
..*  .**  .**  ..*
.**  .**  .**  ..*
..*  ..*  ..*  .**
.**  ..*  ..*  .**
..*  .**  ..*  .**
.**  .**  ..*  .**
..*  ..*  .**  .**
.**  ..*  .**  .**
..*  .**  .**  .**
.**  .**  .**  .**
\$\endgroup\$
3
  • \$\begingroup\$ @xnor I guess it wasn’t clear whether “complement” includes the outside of the image rectangle. I added the empty column to be safe. \$\endgroup\$ Jun 20 '21 at 21:00
  • \$\begingroup\$ the question saysbool images with same width and height, are 3x2^n images allowed? \$\endgroup\$
    – Razetime
    Jun 21 '21 at 6:02
  • \$\begingroup\$ @Razetime The question means that the widths of the \$n\$ images are the same and the heights of the \$n\$ images are the same, not that the width equals the height. See the question’s examples. \$\endgroup\$ Jun 21 '21 at 7:39
5
\$\begingroup\$

Jelly, 12 10 9 8 7 6 bytes

4,6Bṗz

Try it online!

Returns a list of binary matrices (that is, a 3D list).

Output for \$n=6\$, transposed and ASCII-artified:

################################################################
................................################################
................................................................

################################################################
................################................################
................................................................

################################################################
........########........########........########........########
................................................................

################################################################
....####....####....####....####....####....####....####....####
................................................................

################################################################
..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##..##
................................................................

################################################################
.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
................................................................

Explanation

4,6Bṗz Main monadic link, taking n as the argument
4,6    [4,6]
   B   Convert to binary: [[1,0,0],[1,1,0]]
    ṗ  Cartesian power to n
     z Zip with filler n (since it's already a rectangle, the filler will be ignored)
\$\endgroup\$
0
\$\begingroup\$

R, 64 bytes

function(n)Map(function(i)rbind(1,(1:(2^n)-1)%/%2^i%%2,0),1:n-1)

Try it online!

Port of Anders Kaseorg's approach - upvote that one!

\$\endgroup\$
0
\$\begingroup\$

05AB1E, 8 bytes

46SbIãIζ

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ You can remove the second I (or just use ø instead of ). \$\endgroup\$ Aug 12 '21 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.