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 &nbsp; &nbsp; <tt> BBC BASIC. </tt>
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.*/
<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 i=2 while @.i\==''; m=i-1
do j=2 while @.j\==''; p=j-1 /*P is the previous.*/
what=' 'word("< ≥", 1+(FNorder(@.m, @.i)=='false'))" "
answer=FNorder(@.p, @.j) /*obtain the answer.*/
say right('['@.m"]", 35) what '['@.i"]"; say
if answer=='true' then is= ' < ' /*convert from true */
end /*i*/
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); wy=words(y)
FNorder: procedure; parse arg x,y; wx=words(x); wy=words(y)


do j=1 for min(wx,wy)
do k=1 for min(wx,wy)
if word(x,j)<word(y,j) then return 'true'
a=word(x,k); b=word(y,k)
end /*j*/
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>