Task
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order   N.



For example, the Sierpinski carpet of order   3   should look like this:

###########################
# ## ## ## ## ## ## ## ## #
###########################
###   ######   ######   ###
# #   # ## #   # ## #   # #
###   ######   ######   ###
###########################
# ## ## ## ## ## ## ## ## #
###########################
#########         #########
# ## ## #         # ## ## #
#########         #########
###   ###         ###   ###
# #   # #         # #   # #
###   ###         ###   ###
#########         #########
# ## ## #         # ## ## #
#########         #########
###########################
# ## ## ## ## ## ## ## ## #
###########################
###   ######   ######   ###
# #   # ## #   # ## #   # #
###   ######   ######   ###
###########################
# ## ## ## ## ## ## ## ## #
###########################

The use of the   #   character is not rigidly required for ASCII art.

The important requirement is the placement of whitespace and non-whitespace characters.



Related task

   Sierpinski triangle


 
in_carpet(X, Y) =>
    while (X != 0, Y != 0)
        if (X mod 3 == 1, Y mod 3 == 1) then
            false
        end,
        X := X div 3,
        Y := Y div 3
    end.
 
in_carpet(_, _) =>
    true.
 
main(Args) =>
    N = to_int(Args[1]),
    Power1 = 3 ** N - 1,
    foreach (I in 0..Power1)
        foreach (J in 0..Power1)
            printf("%w", cond(in_carpet(I, J), "*", " "))
        end,
        nl
    end.
 