RosettaCodeData/Task/Binary-search/Icon/binary-search-1.icon

12 lines
280 B
Plaintext

procedure binsearch(A, target)
if *A = 0 then fail
mid := *A/2 + 1
if target > A[mid] then {
return mid + binsearch(A[(mid+1):0], target)
}
else if target < A[mid] then {
return binsearch(A[1+:(mid-1)], target)
}
return mid
end