-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (32 loc) · 1.04 KB
/
Copy pathmain.py
File metadata and controls
49 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
if __name__ != "__main__":
exit(1)
from br import br
from clear import clear
clear()
print("Input your numbers separated by spaces. > ")
nums = [int(i) for i in input().split()]
br() # ==================================================
print("Sorting array...")
nums = sorted(nums)
hi = nums.index(max(nums))
lo = nums.index(min(nums))
print(f"Done! New array => {' '.join([str(i) for i in nums])}")
br() # ==================================================
print("What number you want to find? > ")
toFind = int(input())
found: int = None
br() # ==================================================
pointer: int = None
while True:
pointer = round((hi + lo) / 2)
print(f"Pointer: I={pointer} V={nums[pointer]}")
if nums[pointer] < toFind:
lo = pointer
print(f"New low: {nums[lo]} at index {lo}")
elif nums[pointer] > toFind:
hi = pointer
print(f"New high: {nums[hi]} at index {hi}")
elif nums[pointer] == toFind:
found = nums[pointer]
print(f"Found {found} at index {nums.index(found)} (sorted).")
break