Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,31 +1,25 @@
/*REXX program sorts a stemmed array using the gnome-sort algorithm.*/
call gen@ /*generate the @. array elements.*/
call show@ 'before sort' /*show "before" array elements.*/
call gnomeSort # /*invoke the infamous gnome sort.*/
call show@ ' after sort' /*show "after" array elements.*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────GNOMESORT subroutine────────────────*/
gnomeSort: procedure expose @.; parse arg n; k=2 /*n=num items.*/
do j=3 while k<=n; km=k-1 /*KM=prev item*/
if @.km<<=@.k then do; k=j; iterate; end /*OK so far···*/
_=@.km; @.km=@.k; @.k=_ /*swap 2 entries in the @. array.*/
k=k-1; if k==1 then k=j; else j=j-1 /*test index 1*/
end /*j*/ /* [↑] perform gnome sort on @.*/
/*REXX program sorts a stemmed array using the gnome sort algorithm. */
call gen; w=length(#) /*generate @ array; W is width of #.*/
call show 'before sort' /*display the "before" array elements.*/
say copies('',60) /*show a separator line between sorts. */
call gnomeSort # /*invoke the well─known gnome sort. */
call show ' after sort' /*display the "after" array elements.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────GNOMESORT subroutine──────────────────────*/
gnomeSort: procedure expose @.; parse arg n; k=2 /*N: is number items.*/
do j=3 while k<=n; p=k-1 /*P: is previous item*/
if @.p<<=@.k then do; k=j; iterate; end /*array is OK so far.*/
_=@.p; @.p=@.k; @.k=_ /*swap two @ entries.*/
k=k-1; if k==1 then k=j; else j=j-1 /*test for 1st index.*/
end /*j*/
return
/*──────────────────────────────────GEN@ subroutine─────────────────────*/
gen@: !=... 'deadbeef'x ...; @.=! /*default none-value; allows null*/
@.1 = '---the seven virtues---' /* [↓] indent the seven virtues.*/
@.2 = '=======================' ; @.6 = 'Fortitude'
@.3 = 'Faith' ; @.7 = 'Justice'
@.4 = 'Hope' ; @.8 = 'Prudence'
@.5 = 'Charity [Love]' ; @.9 = 'Temperance'
do #=1 while @.#\==!; end /*find the # of items in @ array.*/
#=#-1 /*adjust the numer of items by 1.*/
return
/*──────────────────────────────────SHOW@ subroutine────────────────────*/
show@: do j=1 for # /* [↓] display all items for @. */
say ' element' right(j,length(#)) arg(1)":" @.j
end /*j*/ /* [↑] right justify the J num.*/
say copies('',60) /*show a separator line that fits*/
/*──────────────────────────────────GEN subroutine────────────────────────────*/
gen: @.=; @.1 = '---the seven virtues---' ; @.5 = 'Charity [Love]'
@.2 = '=======================' ; @.6 = 'Fortitude'
@.3 = 'Faith' ; @.7 = 'Justice'
@.4 = 'Hope' ; @.8 = 'Prudence'
@.9 = 'Temperance'
do #=1 while @.#\==''; end; #=#-1 /*determine number of items in @ array.*/
return
/*──────────────────────────────────SHOW subroutine───────────────────────────*/
show: do j=1 for #; say ' element' right(j,w) arg(1)":" @.j; end; return