Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Sierpinski-triangle/NetRexx/sierpinski-triangle.netrexx
Normal file
39
Task/Sierpinski-triangle/NetRexx/sierpinski-triangle.netrexx
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
numeric digits 1000
|
||||
runSample(arg)
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method runSample(arg) public static
|
||||
BLACK_UPPOINTING_TRIANGLE = '\u25b2'
|
||||
parse arg ordr filr .
|
||||
if ordr = '' | ordr = '.' then ordr = 4
|
||||
if filr = '' | filr = '.' then filler = BLACK_UPPOINTING_TRIANGLE
|
||||
else filler = filr
|
||||
drawSierpinskiTriangle(ordr, filler)
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method drawSierpinskiTriangle(ordr, filler = Rexx '^') public static
|
||||
n = 1 * (2 ** ordr)
|
||||
line = ' '.copies(2 * n)
|
||||
line = line.overlay(filler, n + 1) -- set the top point of the triangle
|
||||
loop row = 1 to n -- NetRexx arrays, lists etc. index from 1
|
||||
say line.strip('t')
|
||||
u = filler
|
||||
loop col = 2 + n - row to n + row
|
||||
cl = line.substr(col - 1, 1)
|
||||
cr = line.substr(col + 1, 1)
|
||||
if cl == cr then t = ' '
|
||||
else t = filler
|
||||
line = line.overlay(u, col - 1)
|
||||
u = t
|
||||
end col
|
||||
j2 = n + row - 1
|
||||
j3 = n + row
|
||||
line = line.overlay(t, j2 + 1)
|
||||
line = line.overlay(filler, j3 + 1)
|
||||
end row
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue