Skip to content

Commit a2be3d9

Browse files
authored
Update peg.py
1 parent 8178efb commit a2be3d9

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

peg.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,27 @@
1919
# Boston, MA 02110-1301, USA.
2020
#
2121

22+
def find_smallest(array):
23+
if len(array) == 1:
24+
return 0
25+
elif len(array) == 2:
26+
if array[0] <= array[1]:
27+
return 0
28+
else:
29+
return 1
30+
else:
31+
arrayA = array[:len(array)/2]
32+
arrayB = array[(len(array)/2):]
33+
smallA = find_smallest(arrayA)
34+
smallB = find_smallest(arrayB)
35+
if arrayA[smallA] <= arrayB[smallB]:
36+
return smallA
37+
else:
38+
return len(arrayA) + smallB
39+
40+
41+
2242
import numpy as np
23-
from find_smallest import find_smallest
2443
import copy
2544

2645
class peg():

0 commit comments

Comments
 (0)