import random

def selection_sort(alist):
    count = 0
    count2 = 0
    numpasses = len(alist) - 1

    for i in range(numpasses):
        minidx = i
        for j in range(i+1, len(alist)):
            count += 1
            if alist[j] < alist[minidx]:
                minidx = j  # this keeps track of where the min value is

        # swap the element at maxidx with the element at the "end"
        count2 += 1
        temp = alist[minidx]
        alist[minidx] = alist[i]
        alist[i] = temp

        print(f'after pass number {i} list is: {alist}')

    return (count, count2)


#mylist = [1,7,4,5,2,15,12,50,40,30,11,12,17,16,22,21]
mylist = []
for _ in range(16):
    mylist.append(random.randint(1,50))

print(f'Before sorting with selectionsort:\n   {mylist}')

(numcompares, numswaps) = selection_sort(mylist)

print(f'After sorting with selectionsort:\n   {mylist}')
print(f'Number of compares = {numcompares}, Number of copies = {3*numswaps}')
