I have reworked my submission to use my own sorting routine.
I decided to go with a Cocktail Shaker sort, a bidirectional Bubble sort.
I’ve been looking for an opportunity to do something using mutual recursion.
I found it quite challenging to get all the bugs out.
I guess there is a reason behind not trying to reinvent the wheel.
def bubble_up(a_list,l,k):
if k > 1 :
i = l
j = a_list.index(max(a_list[l:k+l]))
if i != j :
a_list[i], a_list[j] = a_list[j], a_list[i]
sink_down(a_list,l+1,k-1)
def sink_down(a_list,l,k):
if k > 1 :
i = k+l-1
j = a_list.index(min(a_list[l:k+l]))
if i != j :
a_list[i], a_list[j] = a_list[j], a_list[i]
bubble_up(a_list,l,k-1)
def shaker_sort(a_list):
bubble_up(a_list, 0, len(a_list))
return a_list
def scoreSettler(scoreList, maxScore):
return shaker_sort([score for score in scoreList if score <= maxScore])
print(scoreSettler([1, 2, 3, 999999], 1000000))
print(scoreSettler([874300, 879200, 1172100, 1141800, 933900, 1177200, 1190200, 1110100, 1158400, 985600, 1047200, 1049100, 1138600, 1170500, 1064500, 1190000, 1050200, 1090400, 1062800, 1061700, 1218000, 1068000, 1127700, 1144800, 1195100], 1218000))
print(scoreSettler([1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144], 100))
bubble_up
moves larger values toward one end of the list,
while sink_down
moves smaller values toward the other end.
I tried using slices, but soon discovered that they were just copies
and changes to them were not showing up in the list as a whole.
So I passed around the entire list, along with a starting index and
a length, kind of a pseudo-slice.
Here is a repl.it link:
https://repl.it/JRLT/18