Commits

sammyrulez committed 74538b8

working fourth form

Comments (0)

Files changed (2)

 import math
+import sys
 
-def chop(value_to_find,values,current_index = 0):
-
+def chop(value_to_find,values):
+	
 	if len(values) == 0:
 		return -1
+	step = int(math.ceil(0.5+math.sqrt(len(values)-1)))
 	
-	check = values[0]
+	for i in range(0,len(values),step):
+		k = parse_chop(value_to_find,values[i:i+step])
+		if k >= 0:
+			return i + k
+	return -1
 	
-	if check == value_to_find:
-		return current_index
-	else: 
-		abs_lower = abs(values[current_index] - value_to_find)
-		abs_upper = abs(values[len(values)-1] - value_to_find)
-		mid_index =  int(math.floor(len(values)/2))
+		
 
-		if abs_lower < abs_upper:
-			new_values = values[mid_index:len(values)]
-			return chop(value_to_find,new_values,mid_index)
-		else:
-			return chop(value_to_find,values[0:mid_index])
+def parse_chop(value_to_find,values):
+	if len(values) == 0 or value_to_find > values[len(values)-1] or  value_to_find < values[0]:
+		return -sys.maxint  
+	elif value_to_find == values[0]:
+		return 0
+	else:
+		return 1+parse_chop(value_to_find,values[1:len(values)])
+		
+
+		
 	
 	
     def test_chop_three(self):
         from three.chopper import chop as chop_three
         self.chop_kata_moves(chop_three)
-		
-    def test_chop_three(self):
-        from three.chopper import chop as chop_three
-        self.chop_kata_moves(chop_three)
-		
-	 
-
-    #def test_chop_five(self):
-    #    from five.chopper import chop as chop_five
-    #    self.chop_kata_moves(chop_five)
+ 
+    def test_chop_four(self):
+        from four.chopper import chop as chop_four
+        self.chop_kata_moves(chop_four)
 
 
 if __name__ == '__main__':