Abelian sandpile model/Identity: Difference between revisions

m
→‎{{header|REXX}}: added/changed some whitespace and comments, aligned some statements.
No edit summary
m (→‎{{header|REXX}}: added/changed some whitespace and comments, aligned some statements.)
Line 2,654:
<lang rexx>/*REXX program demonstrates a 3x3 sandpile model by addition with toppling & avalanches.*/
@.= 0; size= 3 /*assign 0 to all grid cells; grid size*/
call init 1, 1 2 0 2 1 1 0 1 3 /* " grains of sand-->sand──► sandpile 1. */
call init 2, 2 1 3 1 0 1 0 1 0 /* " " " " " " 2 */
call init 3, 3 3 3 3 3 3 3 3 3 /* " " " " " " 3 */
Line 2,683:
end /*r*/; say arg(4); call norm t; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
eq?: parse arg x, y; xx= tran(x); yy= tran(y); ?= 1
do r=1 for size; do c=1 for size; ?= ? & (@.xx.r.c==@.yy.r.c)
end /*c*/
end /*r*/
if ? then say 'comparison of ' xx " and " yy': same.'
else say 'comparison of ' xx " and " yy': not the same.'
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 2,696:
end /*r*/; shows= 0; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
norm: procedure expose @. size; parse arg x; xx= tran(x); recurse= 0
do r=1 for size; do c=1 for size; if @.xx.r.c<=size then iterate
recurse= 1; @.xx.r.c= @.xx.r.c - 4
call @set xx, r-1, c , @get(xx, r-1, c ) + 1
call @set xx, r+1, c , @get(xx, r+1, c ) + 1
call @set xx, r , c-1, @get(xx, r , c-1) + 1
call @set xx, r , c+1, @get(xx, r , c+1) + 1
end /*c*/
end /*r*/; if recurse then call norm xx; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: parse arg x; xx= tran(x); say ind center("sandpile" xx,25,'─') /*show the title*/
do r=1 for size; $=; do c=1 for size; $= $ @.xx.r.c /*build a row. */
end /*c*/
say ind pad $ /*display a row.*/
end /*r*/; shows= shows + 1; if shows==1 then say; return</lang>