""" Practice coding some given algorithms.
Review lists, for-loops, recursion.
Practice coding, don't worry about the sorting algorithms!
"""
import math
import lec19_given

def indexOfMin(y, iStart):
    """ Returns: index of min value in fragment of y starting at index iStart
    Preconditions: y is a list of numbers (ints, floats) and y[iStart:] is
    not an empty list, i.e., iStart is an int and 0 <= iStart <= len(y).
    """
    minSoFarIndex= iStart
    minSoFar= y[iStart]
    for k in range(iStart,len(y)):
        if y[k] < minSoFar:
            minSoFar= y[k]
            minSoFarIndex= k
    return minSoFarIndex

def selectionSort(y):
    """ Modifies list y such that it is sorted in ascending order
    Precondition: y is a list of numbers (ints, floats)
    """
    # Find the kth smallest value in y; put it in kth position
    for k in range(len(y)):
        # k is beginning of unsorted segment
        i = indexOfMin(y, k)
        # Swap y[i] and y[k]
        tmp= y[i]
        y[i]= y[k]
        y[k]= tmp

def mergeSort(y):
    """ Modifies list y such that its elements are in ascending order.
    Precondition: y is a list of numbers (ints, floats)
    """
    # deal with small data (base case)
    # nothing to do (nothing to modify if len(y)<=1)

    if len(y)>1:
        # break up problem ands solve each part
        mid= len(y)//2
        L= y[:mid]
        R= y[mid:]
        mergeSort(L)
        mergeSort(R)
        # combine result
        lec19_given.merge(y,L,R)


#         0   1   2    3    4    5   6   7
budget= [65,  5,  28, 23.6, 85, 35, 80, 65]
tomatoe= [75, 66, 62, 89,   89,  3, 26, 82]
title= ['Zathura', 'Zero Effect', 'Zoolander', 'Zombieland',
'Zodiac', 'Zoom', 'The Legend of Zorro', 'The Mask of Zorro']

print(budget)
mergeSort(budget)
print(budget)

"""
idx= indexOfMin(budget, 3)
print(idx)
print(budget[idx])
print(title[idx])
"""

"""
good= 70
minSoFar= math.inf
minSoFarIndex= -len(budget)-1
for k in range(0,len(budget)):
    if budget[k] < minSoFar and tomatoe[k]>good:
        minSoFar= budget[k]
        minSoFarIndex= k

if minSoFar==math.inf:
    print('no movie meets my criteria')
else:
    print('Min budget is of good movie ' + str(minSoFar))
    print('And it is ' + title[minSoFarIndex])
"""
