Commits

s...@whiteiron.local  committed 2d2d176

base model for second form of this kata completed

  • Participants
  • Parent commits d514c12

Comments (0)

Files changed (1)

File two/chopper.py

 __author__ = 'sam'
+import math
+
+def check_index_value(mid_index, value_to_find, values):
+    if value_to_find == values[mid_index]:
+        return 0
+    else:
+        return -1
+
 
 def chop(value_to_find,values):
-    pass
+    mid_index = int(math.floor(len(values)/2))
+
+    while mid_index >= 0 and mid_index < len(values) and len(values) > 0 :
+       
+        if mid_index == 0:
+            return check_index_value(mid_index, value_to_find, values)
+
+        elif value_to_find == values[mid_index]:
+            return mid_index
+        else:
+            half_mid_index = int( math.ceil(float(mid_index) / 2))
+            if half_mid_index == 0:
+                return check_index_value(0, value_to_find, values)
+            elif value_to_find > values[mid_index]:
+               mid_index = mid_index + half_mid_index
+            else:
+               mid_index = mid_index - half_mid_index
+
+    return -1
+
+
+
+