Sierpinski triangle: Difference between revisions

m
(→‎{{header|J}}: whitespace helps with parsing verbs)
Line 1,029:
/*REXX program draws a Sierpinksi triangle of any order. */
 
parse arg m mk . /*get the order of the triangle. */
if m=='' | m==',' then m=4 /*if none specified, assume 4. */
if 1mk=='f1' then mk='af*'x /*ifuse EBCDIC,the choosedefault aof bulletan (∙)asterisk.*/
if length(mk)==2 then mk=x2c(mk) /*MK was specified in hexadecimal*/
numeric digits 2000 /*just in case they want a bigun.*/
call sierpinkski_triangle m /*let's rock 'n roll. */
exit
 
 
/*─────────────────────────────────────SIERPINKSKI_TRIANGLE subroutine──*/
sierpinkski_triangle: procedure expose mk; parse arg n .
do j=0 tofor n*4-1
if 1=='f1' then mk='af'x /*if EBCDIC, choose a bullet (∙).*/
else mk='1e'x /*if ASCII, choose triangle (▲).*/
 
if n>8 then if 1=='f1' then mk='9f'x /*if EBCDIC, choose big box (█). */
else mk='db'x /* " ASCII, " " " " */
do j=0 to n*4-1
!=1
_=left('',n*4-1-j)
do k=0 to j
if !//2==0 then _=_' '
else _=_ mk
!=!*(j-k)%(k+1)
end
say _
end
Line 1,057 ⟶ 1,053:
Output (using the default of order 4):
<pre style="height:40ex;overflow:scroll">
*
* *
* *
* * * *
* *
* * * *
* * * *
* * * * * * * *
* *
* * * *
* * * *
* * * * * * * *
* * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * *
</pre>
Output when using the input of:
<br><br>
8 18
8
<pre style="height:30ex;overflow:scroll">
Line 1,113 ⟶ 1,109:
Output when using the input of:
<br><br>
32 db
<pre style="height:30ex;overflow:scroll">