2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,22 +1,21 @@
|
|||
/*REXX program displays a spiral in a square array (of any size). */
|
||||
parse arg size . /*get the array size from the CL.*/
|
||||
if size=='' then size=5 /*No argument? Then use default.*/
|
||||
tot=size**2 /*total # of elements in spiral.*/
|
||||
k=size /*K is the counter for the spiral*/
|
||||
row=1; col=0; start=0 /*start at row 1, col 0, with 0.*/
|
||||
/*──────────────────────────────────────────────construct the spiral #s.*/
|
||||
do n=start for k; col=col+1; @.col.row=n; end; if k==0 then exit
|
||||
/* [↑] build first row of spiral*/
|
||||
do until n>=tot /*spiral matrix.*/
|
||||
do one=1 to -1 by -2 until n>=tot; k=k-1 /*perform twice.*/
|
||||
do n=n for k; row=row+one; @.col.row=n; end /*for the row···*/
|
||||
do n=n for k; col=col-one; @.col.row=n; end /* " " col···*/
|
||||
end /*one*/ /* ↑↓ direction.*/
|
||||
end /*until n≥tot*/ /* [↑] done with matrix spiral.*/
|
||||
/*──────────────────────────────────────────────display spiral to screen*/
|
||||
do row=1 for size; _= /*construct display row by row.*/
|
||||
do col=1 for size /*construct a line col by col.*/
|
||||
_=_ right(@.col.row, length(tot)) /*construct a line for display. */
|
||||
end /*col*/ /* [↑] line has an extra blank.*/
|
||||
say substr(_,2) /*SUBSTR ignores the first blank.*/
|
||||
end /*row*/ /*stick a fork in it, we're done.*/
|
||||
/*REXX program displays a spiral in a square array (of any size) from a start number.*/
|
||||
parse arg size . /*obtain optional arguments from the CL*/
|
||||
if size=='' | size=="," then size=5 /*Not specified? Then use the default.*/
|
||||
tot=size**2; L=length(tot) /*total number of elements in spiral. */
|
||||
k=size /*K: is the counter for the spiral. */
|
||||
row=1; col=0; start=0 /*start spiral at row 1, column 0. */
|
||||
/* [↓] construct the numbered spiral. */
|
||||
do n=start for k; col=col+1; @.col.row=n; end; if k==0 then exit
|
||||
/* [↑] build the first row of spiral. */
|
||||
do until n>=tot /*spiral matrix.*/
|
||||
do one=1 to -1 by -2 until n>=tot; k=k-1 /*perform twice.*/
|
||||
do n=n for k; row=row+one; @.col.row=n; end /*for the row···*/
|
||||
do n=n for k; col=col-one; @.col.row=n; end /* " " col···*/
|
||||
end /*one*/ /* ↑↓ direction.*/
|
||||
end /*until n≥tot*/ /* [↑] done with the matrix spiral. */
|
||||
/* [↓] display spiral to the screen. */
|
||||
do r=1 for size; _= right(@.1.r, L) /*construct display row by row. */
|
||||
do c=2 for size-1; _=_ right(@.c.r, L) /*construct a line for the display. */
|
||||
end /*col*/ /* [↑] line has an extra leading blank*/
|
||||
say _ /*display a line (row) of the sprial. */
|
||||
end /*row*/ /*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
/*REXX program displays a spiral in a square array (of any size). */
|
||||
parse arg size . /*get the array size from the CL.*/
|
||||
if size=='' then size=5 /*No argument? Then use default.*/
|
||||
tot=size**2 /*total # of elements in spiral.*/
|
||||
k=size /*K is the counter for the spiral*/
|
||||
row=1; col=0; start=0 /*start at row 1, col 0, with 0.*/
|
||||
/*──────────────────────────────────────────────construct the spiral #s.*/
|
||||
do n=start for k; col=col+1; @.col.row=n; end; if k==0 then exit
|
||||
/* [↑] build first row of spiral*/
|
||||
do until n>=tot /*spiral matrix.*/
|
||||
do one=1 to -1 by -2 until n>=tot; k=k-1 /*perform twice.*/
|
||||
do n=n for k; row=row+one; @.col.row=n; end /*for the row···*/
|
||||
do n=n for k; col=col-one; @.col.row=n; end /* " " col···*/
|
||||
end /*one*/ /* ↑↓ direction.*/
|
||||
end /*until n≥tot*/ /* [↑] done with matrix spiral.*/
|
||||
/*──────────────────────────────────────────────display spiral to screen*/
|
||||
do twice=0 for 2; if \twice then !.=0 /*1st time? Find max col width.*/
|
||||
do row=1 for size; _= /*construct display row by row. */
|
||||
do col=1 for size; x=@.col.row /*construct a line col by col. */
|
||||
if twice then _=_ right(x,!.col) /*construct a line for display.*/
|
||||
else !.col=max(!.col,length(x)) /*find width of column*/
|
||||
end /*col*/ /* [↓] line has an extra blank.*/
|
||||
if twice then say substr(_,2) /*SUBSTR ignores the 1st blank. */
|
||||
end /*row*/ /*stick a fork in it, we're done*/
|
||||
end /*twice*/
|
||||
/*REXX program displays a spiral in a square array (of any size) from a start number.*/
|
||||
parse arg size . /*obtain optional arguments from the CL*/
|
||||
if size=='' | size=="," then size=5 /*Not specified? Then use the default.*/
|
||||
tot=size**2; L=length(tot) /*total number of elements in spiral. */
|
||||
k=size /*K: is the counter for the spiral. */
|
||||
row=1; col=0; start=0 /*start spiral at row 1, column 0. */
|
||||
/* [↓] construct the numbered spiral. */
|
||||
do n=start for k; col=col+1; @.col.row=n; end; if k==0 then exit
|
||||
/* [↑] build the first row of spiral. */
|
||||
do until n>=tot /*spiral matrix.*/
|
||||
do one=1 to -1 by -2 until n>=tot; k=k-1 /*perform twice.*/
|
||||
do n=n for k; row=row+one; @.col.row=n; end /*for the row···*/
|
||||
do n=n for k; col=col-one; @.col.row=n; end /* " " col···*/
|
||||
end /*one*/ /* ↑↓ direction.*/
|
||||
end /*until n≥tot*/ /* [↑] done with the matrix spiral. */
|
||||
!.=0 /* [↓] display spiral to the screen. */
|
||||
do two=0 for 2 /*1st time? Find max column and width.*/
|
||||
do r=1 for size; _= /*construct display row by row. */
|
||||
do c=1 for size; x=@.c.r /*construct a line column by column. */
|
||||
if two then _=_ right(x, !.c) /*construct a line for the display. */
|
||||
else !.c=max(!.c, length(x)) /*find the maximum width of the column.*/
|
||||
end /*c*/ /* [↓] line has an extra leading blank*/
|
||||
if two then say substr(_,2) /*this SUBSTR ignores the first blank. */
|
||||
end /*r*/
|
||||
end /*two*/ /*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue