Convergence using find?

Dar Scott dsc at swcp.com
Wed Apr 7 17:10:35 EDT 2004


On Wednesday, April 7, 2004, at 02:47 PM, Glen Bojsza wrote:

> I was wondering if anyone has suggestions for converging to the 
> nearest number ( if the desired number doesn't exist) in a sorted 
> field?

Get the field.  Use 'sort', then do a modified "binary search".  The 
chunk 'line i' is expensive for long lists, so actually break up the 
data in the binary search.

For the modified "binary search" maybe something like this would work:  
If there are < 3 lines in your list do something special (I'll leave 
that up to you).  Otherwise, do this:  Get the middle line.  If the 
target is greater, then the best is in the latter lines including the 
middle one.  If the target is less, then the best is in the earlier 
ones including the middle one.

I don't like the counting lines part; you might be better to keep up 
with the line count or switch to arrays.  I bet with some thought you 
can come up with a way to do only one line counting operation per cycle 
or recursion.

Dar Scott



More information about the use-livecode mailing list