# Make a 2d menger sponge [duplicate]

A menger sponge is a fractal made out of cubes within cubes within cubes...

If you start with a cube, on each face there are 9 squares. The middle square becomes empty (or 0). The other 8 squares iterate this process. They each get split up into 9 squares and the middle square face is taken out.

The goal today is to generate a menger sponge face, not the cube.

Here are some example given an input for the number of iterations.

0:
1
(No holes or anything, solid face)

1:
1 1 1
1 0 1
1 1 1

2:
111111111
101101101
111111111
111000111
101000101
111000111
111111111
101101101
111111111

To complete the challenge, based on an input, return a set of 1 (filled in blocks) and 0 (empty blocks) with spaces between or not.

This is code golf, lowest number of bytes wins.

• Also known as a Sierpinski carpet Commented Sep 24, 2017 at 13:04

# SOGL V0.12, 19 bytes

1¹.{³³┼┼≥:10ŗ;┼┼⁴++

Try it Here!

1¹                   push [1]
.{                 input times do
³³                 duplicate top of stack 4 times, resulting in 5 total copies in the stack
┼┼               join the last 3 copies horizontally together
≥              put the joined at the bottom of the stack
:             duplicate top of stack again
10ŗ          replace 1 with 0 only in the top item
;         swap the top 2 items
┼┼       join the top 3 items horizontally together
⁴      copy the item one below top of stack