@@ -89,8 +89,8 @@ def ite_ternary_search(array: list[int], target: int) -> int:
89
89
if right - left < precision :
90
90
return lin_search (left , right , array , target )
91
91
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
94
94
95
95
if array [one_third ] == target :
96
96
return one_third
@@ -138,8 +138,8 @@ def rec_ternary_search(left: int, right: int, array: list[int], target: int) ->
138
138
if left < right :
139
139
if right - left < precision :
140
140
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
143
143
144
144
if array [one_third ] == target :
145
145
return one_third
@@ -157,6 +157,10 @@ def rec_ternary_search(left: int, right: int, array: list[int], target: int) ->
157
157
158
158
159
159
if __name__ == "__main__" :
160
+ import doctest
161
+
162
+ doctest .testmod ()
163
+
160
164
user_input = input ("Enter numbers separated by comma:\n " ).strip ()
161
165
collection = [int (item .strip ()) for item in user_input .split ("," )]
162
166
assert collection == sorted (collection ), f"List must be ordered.\n { collection } ."
0 commit comments