Browse Source

Start to a search algorithm Cameron came up with and we're programming

master
stew3254 3 years ago
commit
84ed4e02f9
No known key found for this signature in database GPG Key ID: FB009CFA64C95CDE
  1. 34
      search.py

34
search.py

@ -0,0 +1,34 @@
#!/usr/bin/python3
import time
x = [i for i in range(10)]
y = [i for i in range(100,110)]
z = sorted([1,3,5,6,8,3,3,5,5,77,9,7,4,333,34])
def search(inp, array):
minimum = array[0]
maximum = array[-1]
step = 1
while True:
if minimum > inp or maximum < inp:
return -1, -1
index = round((inp - minimum)/(maximum - minimum)*len(array))
print(index, array[index])
time.sleep(.25)
if array[index] == inp:
return index, step
elif array[index] < inp:
minimum = array[index]
elif array[index] > inp:
maximum = array[index]
elif minimum == array[index]:
index += 1
step += 1
print(z)
print(search(8, z))
Loading…
Cancel
Save