Browse Source

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

stew3254 1 year ago
commit
84ed4e02f9
No account linked to committer's email address
1 changed files with 34 additions and 0 deletions
  1. 34
    0
      search.py

+ 34
- 0
search.py View File

@@ -0,0 +1,34 @@
1
+#!/usr/bin/python3
2
+
3
+import time
4
+
5
+x = [i for i in range(10)]
6
+y = [i for i in range(100,110)]
7
+z = sorted([1,3,5,6,8,3,3,5,5,77,9,7,4,333,34])
8
+
9
+def search(inp, array):
10
+    minimum = array[0]
11
+    maximum = array[-1]
12
+
13
+    step = 1
14
+    while True:
15
+        if minimum > inp or maximum < inp:
16
+            return -1, -1
17
+
18
+        index = round((inp - minimum)/(maximum - minimum)*len(array))
19
+        
20
+        print(index, array[index])
21
+        time.sleep(.25)
22
+        if array[index] == inp:
23
+            return index, step
24
+        elif array[index] < inp:
25
+            minimum = array[index]
26
+        elif array[index] > inp:
27
+            maximum = array[index]
28
+        elif minimum == array[index]:
29
+            index += 1 
30
+        step += 1
31
+            
32
+
33
+print(z)
34
+print(search(8, z))

Loading…
Cancel
Save