Order two numerical lists: Difference between revisions
Content added Content deleted
(Add Nimrod) |
(→{{header|REXX}}: corrected program, changed comments, simplified conversion of answer to a glyph.) |
||
Line 897: | Line 897: | ||
This R<tt>EXX</tt> example uses the same lists as <tt> BBC BASIC. </tt> |
This R<tt>EXX</tt> example uses the same lists as <tt> BBC BASIC. </tt> |
||
<lang rexx>/*REXX pgm finds if list1<list2 (both contain nums), returns true|false.*/ |
<lang rexx>/*REXX pgm finds if list1<list2 (both contain nums), returns true|false.*/ |
||
@.= |
@. = |
||
@.1=1 2 1 5 2 |
@.1 = 1 2 1 5 2 |
||
@.2=1 2 1 5 2 2 |
@.2 = 1 2 1 5 2 2 |
||
@.3=1 2 3 4 5 |
@.3 = 1 2 3 4 5 |
||
@.4 = 1 2 3 4 5 /* [↓] compare list to previous.*/ |
|||
@.4=1 2 3 4 5 |
|||
do j=2 while @.j\==''; p=j-1 /*P is the previous.*/ |
|||
answer=FNorder(@.p, @.j) /*obtain the answer.*/ |
|||
if answer=='true' then is= ' < ' /*convert from true */ |
|||
else is= ' ≥ ' /*convert from false*/ |
|||
say right('['@.p"]", 40) is '['@.j"]"; say |
|||
end /*i*/ /* [↑] display (+ a blank line)*/ |
|||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
/*──────────────────────────────────FNORDER subroutine──────────────────*/ |
/*──────────────────────────────────FNORDER subroutine──────────────────*/ |
||
FNorder: procedure; parse arg x,y; wx=words(x); |
FNorder: procedure; parse arg x,y; wx=words(x); wy=words(y) |
||
do |
do k=1 for min(wx,wy) |
||
a=word(x,k); b=word(y,k) |
|||
if a<b then return 'true' |
|||
else if a>b then return 'false' |
|||
end /*k*/ |
|||
if wx<wy then return 'true' |
if wx<wy then return 'true' |
||
return 'false'</lang> |
return 'false'</lang> |
||
'''output''' |
'''output''' |
||
<pre> |
<pre> |
||
[1 2 1 5 2] < [1 2 1 5 2 2] |
[1 2 1 5 2] < [1 2 1 5 2 2] |
||
[1 2 1 5 2 2] < [1 2 3 4 5] |
[1 2 1 5 2 2] < [1 2 3 4 5] |
||
[1 2 3 4 5] ≥ [1 2 3 4 5] |
[1 2 3 4 5] ≥ [1 2 3 4 5] |
||
</pre> |
</pre> |
||