Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python A cook has made a stack of pancakes on a skillet. But the pancakes are all of different sizes. Since the cook has

in python

A cook has made a stack of pancakes on a skillet. But the pancakes are all of different sizes. Since the cook has OCD he wants to rearrange the pancakes so that they are in order - the largest pancake is on the bottom and the smallest pancake is on the top. He has a flat spatula that he can insert anywhere in the stack of pancakes and then he can flip all the pancakes on top of the spatula so that they are in reverse order. Using just this one operation of reversing a sub-stack of pancakes devise an algorithm that will allow the cook to sort the stack of pancakes in the fewest number of flips.

Your input is going to be in a file called pancakes.txt. The diameters of the pancakes are expressed as positive integers. There is one or more spaces between each integer. The number of pancakes will vary from 1 to 100. The first number represents the top of the pancake stack and the last number represents the bottom of the pancake stack.

Create an algorithm to sort the stack of pancakes. You may NOT use the built-in sort() function. You may only use the built-in max() and min() functions. You may also reverse, slice and concatenate lists using the built-in Python syntax.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

ISBN: 0764532545, 978-0764532542

More Books

Students also viewed these Databases questions