[@Bernd: here a PONG to your PING.]

Obviously each list member has to be inspected once for the comparison.
And each "smaller than"-member has to be inspected once again to find
the maximum. There is no other way, this is a math fact.

Here is my solution, that seems to be pretty fast.

-- v is a real num, L is a list of real comma-delimites nums
-- if L has NO member < v then return MINVAL (=your setting)
-- Empty members are treated as 0 (doesn't harm, if all x>0)
-- Pre-sorting of L gives no advantage.

function greatestMemberSmallerThan v,L
   put -10^15 into z[true] --> because max(empty)=0
   repeat for each item x in L
      -- if x is empty then next repeat --> here not necessary
      put comma & x after z[x<v]
   end repeat
   return max( z[true] )
end greatestMemberSmallerThan


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to