Pancake Sorting Through List
<p>I am to pancake sort a list and return the minimum number of calls to flipStack. Primarily, I am confused as to why my program doesn't end when the base case is reached (the list is sorted). Shouldn't the best number (minimum number of flips) just be returned right there?</p>

<p>Secondly, I need to add a pruning filter that will get rid of bad flipStack calls resulting in the most minimum number of flips. I think it might have something to do with starting with the largest number but I am confused on how to implement this.</p>

<pre><code>def minFlipsToSort(A):

    return minFlipsToSortHelper(A, 0, [0])

def minFlipsToSortHelper(A, i, best):

    # base case
    if sorted(A) == A:
        return best[0]

    else:
        for j in range(i, len(A)):

            # pruning filter before all this
            flipStack(A, i)
            best[0] +=1
            minFlipsToSortHelper(A, i+1, best)
</code></pre>
