Anonymous user
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 #;
inc= 1; new= new','z
do k=j+1 to #; y= word(old, k) /*get the Kth number in the number list*/
if y\==
inc= inc + 1; g= y /*increase the range, assign G (good).*/
end /*k*/
if k-1=j | g=
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=
say 'old:' old; say 'new:' new /*show the old and new range of numbers*/</lang>
{{out|output|text= 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;
inc= 1; new= new','z
do k=j+1 to #; y= word(old, k) /*get the Kth number in the number list*/
if y\==
inc= inc + 1; g= y /*increase the range, assign G (good).*/
end /*k*/
if k-1=j | g=
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=
say 'old:' old; say 'new:' new /*show the old and new range of numbers*/</lang>
{{out|output|text= is the same as the 1<sup>st</sup> REXX version (1a).}}<br><br>
|