Slashdot Mirror


Pancake Flipping Is Hard — NP Hard

mikejuk writes "French computer scientists have finally proved that sorting pancakes is hard — NP hard. No really — this isn't a joke. Well, it is slightly amusing but that's just because it is being presented as pancake flipping. The algorithm in question is sorting a permutation using prefix reversal — which is much easier to understand in terms of pancakes. Basically you have to sort a pancake stack by simply inserting your spatula and flipping the top part of the stack. We now know that if you can do the this in polynomial time then you have proved that P=NP."

9 of 260 comments (clear)

  1. I'm more interested... by halivar · · Score: 4, Funny

    ...in finding the exact amount of maple syrup I need to pour on a pancake stack to ensure that my bacon is accidentally covered in it.

    Because I would never intentionally put maple syrup on my bacon; that's barbaric.

    1. Re:I'm more interested... by Dunbal · · Score: 3, Informative

      If you used real Canadian maple syrup from real Maple trees instead of that artificial corn syrup crap the rest of the world calls "maple syrup" that tastes like dead beetles, then it really wouldn't matter if you got some on your bacon because everything tastes better with Maple Syrup.

      --
      Seven puppies were harmed during the making of this post.
    2. Re:I'm more interested... by MagicM · · Score: 4, Funny

      that artificial corn syrup crap the rest of the world calls "maple syrup" that tastes like dead beetles

      It's called "beetle juice". It's quite popular in some areas. I love me some beetle juice.

      Mmmm. Beetle juice.

    3. Re:I'm more interested... by fostware · · Score: 4, Funny

      Shhh!

      You'll summon the remake!

      --
      "We know what happens to people who stay in the middle of the road. They get run over." - Aneurin Bevan
    4. Re:I'm more interested... by Rogue+Haggis+Landing · · Score: 5, Informative

      Just go to your nearest Whole Foods (or other real food distributor) and get Grade-B maple syrup. It's not as filtered as the standard Grade-A syrup that most are used to. The flavor is incredible compared to the processed crap that everyone is used to.

      FWIW, maple syrup grades are more dependent on when the trees were tapped than on filtering and processing. (Actually, they're most dependent on what state, provincial, or national body is defining the grades, but that's a different story.) Early in the season, trees produce sap that tends to be higher in sugar and water, and lighter in flavor and color. This sap becomes grade A syrup. As the season progresses, the sap tends to become thicker, less sugary, darker, and stronger flavored, eventually becoming grade B and beyond. This varies from season to season and even from tree to tree, but is generally true.

      If you're really hardcore about your maple, you can round up some Vermont Grade C syrup, "commercial grade", that's usually used in large-scale baking operations. It's extremely thick and strong -- my wife calls it maple sludge. If you like maple, that's as close to the taste of the tree as you can get without gnawing on some bark.

  2. Re:I now understand by frisket · · Score: 5, Funny

    I love this problem. I have been reading about P=NP blah blah blah but never had a solid mental picture. This is great. I get it. Thanks. I wonder how many other mathematical misunderstandings could be cleared up with something as simple as pancakes?

    It's easy: P=pancakes and NP=no pancakes. When P=NP it means you ate them all. The problem is that P-NP != 0 because there's always some maple syrup left on the plate...

  3. Re:Towers of Hanoi? by yakatz · · Score: 3, Informative

    The difference is in where you flip. In the Towers of Hanoi, you do not flip the whole stack, you can only move the pieces one at a time between poles.
    For the pancake problem, you only have one pole and you flip as many as you want at once.
    Good explanation: http://en.wikipedia.org/wiki/Pancake_sorting

  4. Solution? by Erich · · Score: 3, Interesting
    I had something like this was an interview question once. My solution:

    Assume we are stacking pancakes with largest at the bottom.

    1. Find the largest unsorted pancake
    2. Flip that to the top
    3. Flip from the bottom-most unsorted pancake. (One additional pancake is now sorted)
    4. Repeat until sorted

    To me, assuming that you consider "Find the largest unsorted pancake" to be O(N), the algorithm is O(N^2). Number of flips is 2N. Where's my turing award?

    So I must be missing something... Is one not able to find the largest unsorted pancake easily? Perhaps you are only able to look at the size of the topmost pancake. The article was unclear.

    --

    -- Erich

    Slashdot reader since 1997

    1. Re:Solution? by Erich · · Score: 3, Insightful

      Oh, I see. The problem is not that pancake flipping itself is hard, that determining the optimal pancake flipping algorithm for a stack is hard. That's believable.

      --

      -- Erich

      Slashdot reader since 1997