@@ -89,8 +89,8 @@ def ite_ternary_search(array: list[int], target: int) -> int:
8989 if right - left < precision :
9090 return lin_search (left , right , array , target )
9191
92- one_third = (left + right ) / 3 + 1
93- two_third = 2 * (left + right ) / 3 + 1
92+ one_third = (left + right ) // 3 + 1
93+ two_third = 2 * (left + right ) // 3 + 1
9494
9595 if array [one_third ] == target :
9696 return one_third
@@ -138,8 +138,8 @@ def rec_ternary_search(left: int, right: int, array: list[int], target: int) ->
138138 if left < right :
139139 if right - left < precision :
140140 return lin_search (left , right , array , target )
141- one_third = (left + right ) / 3 + 1
142- two_third = 2 * (left + right ) / 3 + 1
141+ one_third = (left + right ) // 3 + 1
142+ two_third = 2 * (left + right ) // 3 + 1
143143
144144 if array [one_third ] == target :
145145 return one_third
@@ -157,6 +157,10 @@ def rec_ternary_search(left: int, right: int, array: list[int], target: int) ->
157157
158158
159159if __name__ == "__main__" :
160+ import doctest
161+
162+ doctest .testmod ()
163+
160164 user_input = input ("Enter numbers separated by comma:\n " ).strip ()
161165 collection = [int (item .strip ()) for item in user_input .split ("," )]
162166 assert collection == sorted (collection ), f"List must be ordered.\n { collection } ."
0 commit comments