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


 
 
PROGRAM SIERP_CARPET
 
! for rosettacode.org
 
!$INTEGER
 
BEGIN
 OPEN("O",1,"OUT.PRN")
 PRINT(CHR$(12);) !CLS
 DEPTH=3
 DIMM=1
 
 FOR I=0 TO DEPTH-1 DO
   DIMM=DIMM*3
 END FOR
 
 FOR I=0 TO DIMM-1 DO
   FOR J=0 TO DIMM-1 DO
     D=DIMM DIV 3
     REPEAT
        EXIT IF ((I MOD (D*3)) DIV D=1 AND (J MOD (D*3)) DIV D=1)
        D=D DIV 3
     UNTIL NOT(D>0)
     IF D>0 THEN PRINT(#1,"  ";)  ELSE PRINT(#1,"##";) END IF
   END FOR
   PRINT(#1,)
 END FOR
 ! PRINT(#1,CHR$(12);) for printer only!
 CLOSE(1)
END PROGRAM
 