RosettaCodeData/Task/Binary-search/Lua/binary-search-1.lua
2023-07-01 13:44:08 -04:00

12 lines
312 B
Lua

function binarySearch (list,value)
local low = 1
local high = #list
while low <= high do
local mid = math.floor((low+high)/2)
if list[mid] > value then high = mid - 1
elseif list[mid] < value then low = mid + 1
else return mid
end
end
return false
end