This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -4,14 +4,14 @@ void main() {
int[n][n] M;
int pos, side = n;
foreach (i; 0 .. (n / 2 + n % 2)) {
foreach (j; 0 .. side)
foreach (immutable i; 0 .. n / 2 + n % 2) {
foreach (immutable j; 0 .. side)
M[i][i + j] = pos++;
foreach (j; 1 .. side)
foreach (immutable j; 1 .. side)
M[i + j][n - 1 - i] = pos++;
foreach_reverse (j; 0 .. side - 1)
foreach_reverse (immutable j; 0 .. side - 1)
M[n - 1 - i][i + j] = pos++;
foreach_reverse (j; 1 .. side - 1)
foreach_reverse (immutable j; 1 .. side - 1)
M[i + j][i] = pos++;
side -= 2;
}

View file

@ -1,28 +1,27 @@
/*REXX program to show a spiral in a square array (of any size). */
arg size . /*get the array size from arg. */
if size=='' then size=5 /*if no argument, use the default*/
/*REXX program displays a spiral in a square array (of any size). */
parse arg size . /*get the array size from arg. */
if size=='' then size=5 /*if no argument, use the default*/
tot=size**2 /*total # of elements in spiral. */
k=size /*K is the counter for the sprial*/
row=1 /*start with row one. */
col=0 /*start with col zero. */
n=0 /*start the sprial at 0 (zero).*/
row=1; col=0 /*start with row one, col zero. */
n=0 /*start the spiral at 0 (zero).*/
/*─────────────────────────────────────build the spiral */
do n=0 for k; col=col+1; @.col.row=n; end; if k==0 then exit
/*─────────────────────────────────────build the spiral─────────────────*/
do n=0 for k; col=col+1; @.col.row=n; end
do until n>=tot
do until n>=tot
k=k-1
do n=n for k; row=row+1; @.col.row=n; end
do n=n for k; col=col-1; @.col.row=n; end
if n>=tot then leave
do n=n for k; row=row+1; @.col.row=n; end
do n=n for k; col=col-1; @.col.row=n; end
if n>=tot then leave
k=k-1
do n=n for k; row=row-1; @.col.row=n; end
do n=n for k; col=col+1; @.col.row=n; end
end
/*─────────────────────────────────────display the spiral───────────────*/
do col=1 for size; _=''
do row=1 for size
_=_ right(@.row.col,length(tot))
end
do n=n for k; row=row-1; @.col.row=n; end
do n=n for k; col=col+1; @.col.row=n; end
end /*DO until n≥tot*/
/*─────────────────────────────────────display the spiral */
do col=1 for size; _=
do row=1 for size
_=_ right(@.row.col, length(tot))
end /*row*/
say substr(_,2)
end
end /*col*/
/*stick a fork in it, we're done.*/