Jump to content

Order two numerical lists: Difference between revisions

→‎{{header|REXX}}: corrected program, changed comments, simplified conversion of answer to a glyph.
(Add Nimrod)
(→‎{{header|REXX}}: corrected program, changed comments, simplified conversion of answer to a glyph.)
Line 897:
This R<tt>EXX</tt> example uses the same lists as &nbsp; &nbsp; <tt> BBC BASIC. </tt>
<lang rexx>/*REXX pgm finds if list1<list2 (both contain nums), returns true|false.*/
@. =
@.1 = 1 2 1 5 2
@.2 = 1 2 1 5 2 2
@.3 = 1 2 3 4 5
@.4 = 1 2 3 4 5 /* [↓] compare list to previous.*/
@.4=1 2 3 4 5
do ij=2 while @.ij\==''; mp=ij-1 /*P is the previous.*/
whatanswer=' 'word("< ≥", 1+(FNorder(@.mp, @.ij)=='false'))" " /*obtain the answer.*/
if say right(answer=='[true'@.m"]", 35) then is= what ' < '['@.i"]"; /*convert from true say*/
end else is= ' ≥ ' /*iconvert from false*/
say right('['@.p"]", 40) is '['@.j"]"; say
end /*i*/ /* [↑] display (+ a blank line)*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────FNORDER subroutine──────────────────*/
FNorder: procedure; parse arg x,y; wx=words(x); wy=words(y)
 
do jk=1 for min(wx,wy)
if a=word(x,jk)<; b=word(y,jk) then return 'true'
endif a<b /*j*/then return 'true'
else if a>b then return 'false'
end /*k*/
if wx<wy then return 'true'
return 'false'</lang>
'''output'''
<pre>
[1 2 1 5 2] < [1 2 1 5 2 2]
 
[1 2 1 5 2 2] < [1 2 3 4 5]
 
[1 2 3 4 5] ≥ [1 2 3 4 5]
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.