ranging lists

Dar Scott dsc at swcp.com
Wed Jan 29 11:02:01 EST 2003


On Wednesday, January 29, 2003, at 04:57 AM, Ron wrote:

> I have 2 lists. I need to check whether the values of list 2 fall 
> within the
> range of the values of list 1. eg.
>
> list 1
> 1 10
> 20 25
> 45 55
>
> list 2
> 1,3,12,23,34,45,52,78

If those are already sorted as your example is, you can exploit that.  
(If not, you might consider sorting them or creating them sorted.)

Here is one way to exploit that:  repeat over the items in list two, 
accumulating those that are in a range in list 2, and then return the 
accumulation.  (Keep up with the current range by line number starting 
with the first.)  To check whether a number is in a range, do two 
things:  First, advance the range line number while the number is not 
above the upper range limit.  (if you run out of ranges, return the 
accumulation.)  Second, if the number is not lower than the lower 
limit, accumulate it.

Dar Scott






More information about the use-livecode mailing list