Range extraction: Difference between revisions

m
→‎{{header|REXX}}: optimized and simplified versions 1a and 1b.
m (→‎{{header|REXX}}: simplified some code.)
m (→‎{{header|REXX}}: optimized and simplified versions 1a and 1b.)
Line 4,618:
#= words(old) /*number of integers in the number list*/
new= /*the new list, possibly with ranges. */
do j=1 to #; xz= word(old, j) /*obtain Jth number in the old list. */
inc= 1; new= new','z x /*append " " to " new " */
do k=j+1 to #; y= word(old, k) /*get the Kth number in the number list*/
if y\==xz+inc then leave /*is this number not > previous by inc?*/
inc= inc + 1; g= y /*increase the range, assign G (good).*/
end /*k*/
if k-1=j | g=xz+1 then iterate /*Is the range=0│1? Then keep truckin'*/
new= new'-'g; j= k - 1 /*indicate a range of #s; change index*/
end /*j*/
/*stick a fork in it, we're all done. */
new= space( substr(new, 2), 0) /*elide the leading comma, alsoin allthe blanksrange.*/
say 'old:' old; say 'new:' new /*show the old and new range of numbers*/</lang>
{{out|output|text=&nbsp; when using the (internal) default list of numbers:}}
Line 4,643:
#= words(old); j= 0 /*number of integers in the number list*/
new= /*the new list, possibly with ranges. */
do while j<#; j= j + 1; xz= word(old, j) /*get the Jth number in the number list*/
inc= 1; new= new','z x /*append " " to " new " */
do k=j+1 to #; y= word(old, k) /*get the Kth number in the number list*/
if y\==xz+inc then leave /*is this number not > previous by inc?*/
inc= inc + 1; g= y /*increase the range, assign G (good).*/
end /*k*/
if k-1=j | g=xz+1 then iterate /*Is the range=0│1? Then keep truckin'*/
new= new'-'g; j= k - 1 /*indicate a range of numbers; change J*/
end /*while*/
/*stick a fork in it, we're all done. */
new= space( substr(new, 2), 0) /*elide the leading comma, alsoin allthe blankslist. */
say 'old:' old; say 'new:' new /*show the old and new range of numbers*/</lang>
{{out|output|text=&nbsp; is the same as the 1<sup>st</sup> REXX version (1a).}}<br><br>