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


/* NetRexx */
options replace format comments java crossref symbols nobinary
 
numeric digits 1000
runSample(arg)
return
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) public static
  DARK_SHADE = '\u2593'
  parse arg ordr filr .
  if ordr = '' | ordr = '.' then ordr = 3
  if filr = '' | filr = '.' then filler = DARK_SHADE
  else                           filler = filr
  drawSierpinskiCarpet(ordr, filler)
  return
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method drawSierpinskiCarpet(ordr, filler = Rexx '@') public static binary
  x = long
  y = long
  powr = 3 ** ordr
  loop x = 0 to powr - 1
    loop y = 0 to powr - 1
      if isSierpinskiCarpetCellFilled(x, y) then cell = filler
      else                                       cell = ' '
      say cell'\-'
      end y
      say
    end x
  return
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method isSierpinskiCarpetCellFilled(x = long, y = long) public static binary returns boolean
  isTrue  = boolean (1 == 1)
  isFalse = \isTrue
  isFilled = isTrue
  loop label edge while x \= 0 & y \= 0
    if x // 3 = 1 & y // 3 = 1 then do
      isFilled = isFalse
      leave edge
      end
    x = x % 3
    y = y % 3
    end edge
  return isFilled
 