September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,12 +1,11 @@
|
|||
/*REXX program constructs & displays Floyd's triangle for any number of specified rows.*/
|
||||
parse arg rows .; if rows=='' then rows=5 /*Not specified? Then use the default.*/
|
||||
mx=rows * (rows+1) % 2 /*calculate maximum value of any value.*/
|
||||
say 'displaying a ' rows " row Floyd's triangle:" /*show header for the triangle.*/
|
||||
parse arg N .; if N=='' | N=="," then N=5 /*Not specified? Then use the default.*/
|
||||
mx=N * (N+1) % 2 - N /*calculate maximum value of any value.*/
|
||||
say 'displaying a ' N " row Floyd's triangle:" /*show the header for Floyd's triangle.*/
|
||||
say
|
||||
#=1; do r=1 for rows; i=0; _= /*construct Floyd's triangle row by row*/
|
||||
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
|
||||
_=_ right(#, length(mx-rows+i)) /*build a row of the Floyd's triangle. */
|
||||
#=1; do r=1 for N; i=0; _= /*construct Floyd's triangle row by row*/
|
||||
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
|
||||
_=_ right(#, length( mx+i ) ) /*build a row of the Floyd's triangle. */
|
||||
end /*#*/
|
||||
say substr(_,2) /*remove 1st leading blank in the line,*/
|
||||
end /*r*/ /* [↑] introduced by first abutment. */
|
||||
/*stick a fork in it, we're all done. */
|
||||
say substr(_, 2) /*remove 1st leading blank in the line.*/
|
||||
end /*r*/ /*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
/*REXX program constructs & displays Floyd's triangle for any number of rows in base 16.*/
|
||||
parse arg rows .; if rows=='' then rows=6 /*Not specified? Then use the default.*/
|
||||
mx=rows * (rows+1) % 2 /*calculate maximum value of any value.*/
|
||||
say 'displaying a ' rows " row Floyd's triangle in base 16:"; say /*show triangle hdr*/
|
||||
#=1
|
||||
do r=1 for rows; i=0; _= /*construct Floyd's triangle row by row*/
|
||||
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
|
||||
_=_ right(d2x(#),length(d2x(mx-rows+i))) /*build a row of the Floyd's triangle. */
|
||||
end /*#*/
|
||||
say substr(_,2) /*remove 1st leading blank in the line,*/
|
||||
end /*r*/ /* [↑] introduced by first abutment. */
|
||||
/*stick a fork in it, we're all done. */
|
||||
parse arg N .; if N=='' | N=="," then N=6 /*Not specified? Then use the default.*/
|
||||
mx=N * (N+1) % 2 - N /*calculate maximum value of any value.*/
|
||||
say 'displaying a ' N " row Floyd's triangle in base 16:" /*show triangle header.*/
|
||||
say
|
||||
#=1; do r=1 for N; i=0; _= /*construct Floyd's triangle row by row*/
|
||||
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
|
||||
_=_ right( d2x(#), length( d2x(mx+i))) /*build a row of the Floyd's triangle. */
|
||||
end /*#*/
|
||||
say substr(_, 2) /*remove 1st leading blank in the line.*/
|
||||
end /*r*/ /*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -1,50 +1,50 @@
|
|||
/*REXX program constructs/shows Floyd's triangle for any number of rows in any base ≤90.*/
|
||||
parse arg rows radx . /*obtain optional arguments from the CL*/
|
||||
if rows=='' | rows=="," then rows= 5 /*Not specified? Then use the default.*/
|
||||
parse arg N radx . /*obtain optional arguments from the CL*/
|
||||
if N=='' | N=="," then N= 5 /*Not specified? Then use the default.*/
|
||||
if radx=='' | radx=="," then radx=10 /* " " " " " " */
|
||||
mx=rows * (rows+1) % 2 /*calculate maximum value of any value.*/
|
||||
say 'displaying a ' rows " row Floyd's triangle in base" radx':'; say /*display hdr*/
|
||||
#=1
|
||||
do r=1 for rows; i=0; _= /*construct Floyd's triangle row by row*/
|
||||
mx=N * (N+1) % 2 - N /*calculate maximum value of any value.*/
|
||||
say 'displaying a ' N " row Floyd's triangle in base" radx':' /*display the header.*/
|
||||
say
|
||||
#=1; do r=1 for N; i=0; _= /*construct Floyd's triangle row by row*/
|
||||
do #=# for r; i=i+1 /*start to construct a row of triangle.*/
|
||||
_=_ right(base(#, radx), length(base(mx-rows+i, radx))) /*build triangle row*/
|
||||
_=_ right(base(#, radx), length( base(mx+i, radx) ) ) /*build triangle row.*/
|
||||
end /*#*/
|
||||
say substr(_,2) /*remove 1st leading blank in the line,*/
|
||||
say substr(_, 2) /*remove 1st leading blank in the line,*/
|
||||
end /*r*/ /* [↑] introduced by first abutment. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
base: procedure; parse arg x 1 ox,toB,inB /*obtain number, toBase, inBase. */
|
||||
@abc='abcdefghijklmnopqrstuvwxyz' /*lowercase Latin alphabet. */
|
||||
@abcU=@abc; upper @abcU /*go whole hog and extend 'em. */
|
||||
@@@='0123456789'@abc || @abcU /*prefix 'em with numeric digits.*/
|
||||
@abc= 'abcdefghijklmnopqrstuvwxyz' /*lowercase Latin alphabet. */
|
||||
@abcU=@abc; upper @abcU /*go whole hog and extend 'em. */
|
||||
@@@= '0123456789'@abc || @abcU /*prefix 'em with numeric digits.*/
|
||||
@@@=@@@'<>[]{}()?~!@#$%^&*_=|\/;:¢¬≈' /*add some special chars as well.*/
|
||||
/*handles up to base 90, all chars must be viewable.*/
|
||||
numeric digits 1000 /*what the hey, support gihugeics*/
|
||||
/* [↑] handles up to base 90, all chars must be viewable.*/
|
||||
numeric digits 3000 /*what the hey, support gihugeics*/
|
||||
mxB=length(@@@) /*max base (radix) supported here*/
|
||||
if toB=='' | toB=="," then toB=10 /*if skipped, assume default (10)*/
|
||||
if inB=='' | inB=="," then inB=10 /* " " " " " */
|
||||
if inB<2 | inb>mxB then call erb 'inBase',inB /*invalid/illegal arg: inBase. */
|
||||
if toB<2 | tob>mxB then call erb 'toBase',toB /* " " " toBase. */
|
||||
if x=='' then call erm /* " " " number. */
|
||||
sigX=left(x,1)
|
||||
if pos(sigX,'-+')\==0 then x=substr(x,2) /*X number has a leading sign? */
|
||||
else sigX= /* ··· no leading sign.*/
|
||||
#=0; do j=1 for length(x) /*convert X, base inB ──► base 10*/
|
||||
_=substr(x, j, 1) /*pick off a numeral from X. */
|
||||
sigX=left(x, 1) /*obtain a possible leading sign.*/
|
||||
if pos(sigX, '-+')\==0 then x=substr(x, 2) /*X number has a leading sign? */
|
||||
else sigX= /* ··· no leading sign.*/
|
||||
#=0
|
||||
do j=1 for length(x); _=substr(x, j, 1) /*convert X, base inB ──► base 10*/
|
||||
v=pos(_, @@@) /*get the value of this "digit". */
|
||||
if v==0 | v>inB then call erd x,j,inB /*is this an illegal "numeral" ? */
|
||||
#=#*inB+v-1 /*construct new num, dig by dig. */
|
||||
#=# * inB + v - 1 /*construct new num, dig by dig. */
|
||||
end /*j*/
|
||||
y=
|
||||
do while # >= toB /*convert #, base 10 ──► base toB*/
|
||||
y=substr(@@@, (#//toB)+1, 1)y /*construct the number for output*/
|
||||
#=#%toB /* ··· and whittle # down also.*/
|
||||
y=substr(@@@, (# // toB) + 1, 1)y /*construct the number for output*/
|
||||
#=# % toB /* ··· and whittle # down also.*/
|
||||
end /*while*/
|
||||
|
||||
y=sigX || substr(@@@, #+1, 1)y /*prepend the sign if it existed.*/
|
||||
return y /*return the number in base toB.*/
|
||||
/*───────────────────────────────────────────────────────────────────────────────────────*/
|
||||
erb: call ser 'illegal' arg(2) "base:" arg(1) "must be in range: 2──►" mxB
|
||||
erd: call ser 'illegal "digit" in' x":" _
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
erb: call ser 'illegal' arg(2) "base: " arg(1) "must be in range: 2──► " mxB
|
||||
erd: call ser 'illegal "digit" in' x":" _
|
||||
erm: call ser 'no argument specified.'
|
||||
ser: say; say '*** error! ***'; say arg(1); say; exit 13
|
||||
ser: say; say '***error***'; say arg(1); say; exit 13
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue