I was thinking a bit like Irv, and that rather than use a property
list, just use a list of integers for the horsepower. There are cuter
ways than Irv's to do it though. You could do this:
uservalue would be the amount the user has entered
on closest uservalue
hplist = [0,1,3,5,7,9,11,13,15,17,45,78,23,85,94,213,1234,the maxinteger]
append hplist,uservalue
sort hplist
userplace = getone(hplist,uservalue)
diff1 = abs(getat(hplist,max(1,userplace-1))-uservalue)
diff2 = abs(getat(hplist,min(count(hplist),userplace+1))-uservalue)
if diff1 > diff2 then
return getat(hplist,max(1,userplace-1))
else
return getat(hplist,min(count(hplist),userplace+1))
end if
end
You'll have to read that carefully! But it does work:
put closest(62)
-- 78
put closest(61)
-- 45
put closest(8)
-- 7
As you can see, in the case of a tie it favors the value below.
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]