How to resolve the algorithm Sierpinski carpet step by step in the NetRexx programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sierpinski carpet step by step in the NetRexx programming language
Table of Contents
Problem Statement
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.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sierpinski carpet step by step in the NetRexx programming language
Source code in the netrexx programming language
/* 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
You may also check:How to resolve the algorithm Palindrome detection step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Numerical integration step by step in the Python programming language
You may also check:How to resolve the algorithm Combinations step by step in the Pop11 programming language
You may also check:How to resolve the algorithm Define a primitive data type step by step in the Frink programming language
You may also check:How to resolve the algorithm GUI component interaction step by step in the Java programming language