Sierpinski carpet
Sierpinski carpet
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Produce an ASCII representation of a Sierpinski carpet of order N. For example, the Sierpinski carpet of order 2 should look like this:
+-------------+-------------+-------------+ |+---+---+---+|+---+---+---+|+---+---+---+| || | | ||| | | ||| | | || |+---+---+---+|+---+---+---+|+---+---+---+| || | | ||| | | ||| | | || |+---+---+---+|+---+---+---+|+---+---+---+| || | | ||| | | ||| | | || |+---+---+---+|+---+---+---+|+---+---+---+| +-------------+-------------+-------------+ |+---+---+---+| |+---+---+---+| || | | || || | | || |+---+---+---+| |+---+---+---+| || | | || || | | || |+---+---+---+| |+---+---+---+| || | | || || | | || |+---+---+---+| |+---+---+---+| +-------------+-------------+-------------+ |+---+---+---+|+---+---+---+|+---+---+---+| || | | ||| | | ||| | | || |+---+---+---+|+---+---+---+|+---+---+---+| || | | ||| | | ||| | | || |+---+---+---+|+---+---+---+|+---+---+---+| || | | ||| | | ||| | | || |+---+---+---+|+---+---+---+|+---+---+---+| +-------------+-------------+-------------+
See also Sierpinski triangle
J
Like the sierpinski triangle, the carpet is easy to produce in J. One way:
(a:(<1;1)}3 3$<)^:2' '
or another:
((#:7 5 7){_2{.<)^:2' '