RosettaCodeData/Task/Binary-search/Pop11/binary-search-2.pop11
2023-07-01 13:44:08 -04:00

16 lines
395 B
Text

define BinarySearch(A, value);
define do_it(low, high);
if high < low then
return("not_found");
endif;
(low + high) div 2 -> mid;
if A(mid) > value then
do_it(low, mid-1);
elseif A(mid) < value then
do_it(mid+1, high);
else
mid;
endif;
enddefine;
do_it(1, length(A));
enddefine;