Date: 31/12/2013 16:53:43
From: Peak Warming Man
ID: 461833
Subject: Pancake Numbers

“Number 22
Pancakes
Simon Singh, author: My number of the year is 22 and it relates to a problem called pancake sorting, created by Jacob Goodman, who was 80 this year.

Imagine you have a stack of pancakes of different sizes and in the wrong order and you want to get them into the right order – say, with the smallest at the top and the largest at the bottom. You can stick a spatula anywhere in the stack and flip over all the pancakes above that point.

If you have two pancakes and they’re in the wrong order then the “pancake number” is one, because you only need one flip to swap them over. For three pancakes, the maximum number of flips required is three.

You can work out the pancake number for various numbers of pancakes, and the number for 19 pancakes is 22. That’s my number of the year because mathematicians have not been able to calculate the pancake number for 20 pancakes.

By the way, the only research paper that Bill Gates ever wrote was on the subject of pancake numbers.”

Reply Quote

Date: 31/12/2013 16:54:16
From: wookiemeister
ID: 461835
Subject: re: Pancake Numbers

mmmm pancakes

Reply Quote

Date: 31/12/2013 17:01:40
From: Bubblecar
ID: 461852
Subject: re: Pancake Numbers

>That’s my number of the year because mathematicians have not been able to calculate the pancake number for 20 pancakes.

Well get on with it lad, make a name for yourself.

Strange it should jump from 22 per 19 to “incalculable” like that.

Reply Quote

Date: 31/12/2013 17:04:51
From: dv
ID: 461855
Subject: re: Pancake Numbers

Maybe it took them decades to work out that the pancake number for 19 is 22. The fact that they haven’t calculate the pancake number for 20 yet doesn’t imply that it is a large number: just that it is hard to calculate.

Reply Quote

Date: 31/12/2013 17:05:50
From: stumpy_seahorse
ID: 461857
Subject: re: Pancake Numbers

Bubblecar said:


>That’s my number of the year because mathematicians have not been able to calculate the pancake number for 20 pancakes.

Well get on with it lad, make a name for yourself.

Strange it should jump from 22 per 19 to “incalculable” like that.

i can’t see why it would take more than 20 flips to sort a stack of 19 pancakes?

and OTTOMH i count 21 flips to sort a stack of 20

Reply Quote

Date: 31/12/2013 17:07:15
From: Divine Angel
ID: 461862
Subject: re: Pancake Numbers

Sounds like it’s time to do the experiment…

Anyone for maple syrup?

Reply Quote

Date: 31/12/2013 17:08:33
From: Bubblecar
ID: 461864
Subject: re: Pancake Numbers

dv said:


Maybe it took them decades to work out that the pancake number for 19 is 22. The fact that they haven’t calculate the pancake number for 20 yet doesn’t imply that it is a large number: just that it is hard to calculate.

Yes, it’s just that without trying it myself, I’d naïvely assume that small numbers like that are manageable enough to work out without too much time & effort. Obviously not.

Reply Quote

Date: 31/12/2013 17:11:44
From: furious
ID: 461870
Subject: re: Pancake Numbers

Probably because when they got that high they realised they wasted their lives and found something better to do…

Reply Quote

Date: 31/12/2013 17:11:45
From: Soso
ID: 461871
Subject: re: Pancake Numbers

Bubblecar said:


>That’s my number of the year because mathematicians have not been able to calculate the pancake number for 20 pancakes.

Well get on with it lad, make a name for yourself.

Strange it should jump from 22 per 19 to “incalculable” like that.

It’s not incalculable as in incalculably large, just unknown. Given the known sequence so far, the number for 20 is probably 23 or 24.

Reply Quote

Date: 31/12/2013 17:14:33
From: The Rev Dodgson
ID: 461873
Subject: re: Pancake Numbers

dv said:


Maybe it took them decades to work out that the pancake number for 19 is 22. The fact that they haven’t calculate the pancake number for 20 yet doesn’t imply that it is a large number: just that it is hard to calculate.

A simple brute force method would require (n-1)^x calculations, where n is the number of pancakes, and x is the minimum number of flips, and that would be for just one arrangement of pancakes.

You’d need (n-1)! trials to cover all possible pancake arrangements, and that comes to quite a large number.

Reply Quote

Date: 31/12/2013 17:16:15
From: Peak Warming Man
ID: 461874
Subject: re: Pancake Numbers

The Rev Dodgson said:


dv said:

Maybe it took them decades to work out that the pancake number for 19 is 22. The fact that they haven’t calculate the pancake number for 20 yet doesn’t imply that it is a large number: just that it is hard to calculate.

A simple brute force method would require (n-1)^x calculations, where n is the number of pancakes, and x is the minimum number of flips, and that would be for just one arrangement of pancakes.

You’d need (n-1)! trials to cover all possible pancake arrangements, and that comes to quite a large number.

Could be almost infinite.

Reply Quote

Date: 31/12/2013 17:17:26
From: The Rev Dodgson
ID: 461876
Subject: re: Pancake Numbers

Peak Warming Man said:


The Rev Dodgson said:

dv said:

Maybe it took them decades to work out that the pancake number for 19 is 22. The fact that they haven’t calculate the pancake number for 20 yet doesn’t imply that it is a large number: just that it is hard to calculate.

A simple brute force method would require (n-1)^x calculations, where n is the number of pancakes, and x is the minimum number of flips, and that would be for just one arrangement of pancakes.

You’d need (n-1)! trials to cover all possible pancake arrangements, and that comes to quite a large number.

Could be almost infinite.

Indeed, by some standards it would be much more than almost infinite, I should think.

Reply Quote

Date: 31/12/2013 20:17:52
From: mollwollfumble
ID: 461986
Subject: re: Pancake Numbers

If P(X) is the number of flips required for X pancakes, it is easy to prove that P(X+1) <= P(X) + 2, for all X.

Reply Quote

Date: 31/12/2013 20:52:28
From: mollwollfumble
ID: 461992
Subject: re: Pancake Numbers

It’s also trivial to prove that if any two pancakes in a stack of X pancakes is initially in either the correct order or the reverse of the correct order then P(X) <= P(X-1)+1

That means that in order to test if P(X) = P(X-1)+2 it is only necessary to start with those stacks for which no two initially adjacent pancakes have a difference of 1 in final position. This reduces the number of tests required for brute force evaluation significantly.

Reply Quote

Date: 31/12/2013 21:04:39
From: mollwollfumble
ID: 461995
Subject: re: Pancake Numbers

Peak Warming Man said:


If you have two pancakes and they’re in the wrong order then the “pancake number” is one, because you only need one flip to swap them over. For three pancakes, the maximum number of flips required is three.

Liar! For three pancakes, the maximum number of flips required is two.

Reply Quote

Date: 31/12/2013 21:09:14
From: mollwollfumble
ID: 461996
Subject: re: Pancake Numbers

Oh wait, sorry. I was assuming that you could flip over either the bottom of the stack or the top of the stack. Oops, the rules say you can only flip the top of the stack. It is 3 flips for 3 pancakes then.

What I said before about P(X+1) <= P(X)+2 still holds.

Reply Quote

Date: 31/12/2013 22:12:03
From: The Rev Dodgson
ID: 462023
Subject: re: Pancake Numbers

mollwollfumble said:


Oh wait, sorry. I was assuming that you could flip over either the bottom of the stack or the top of the stack. Oops, the rules say you can only flip the top of the stack. It is 3 flips for 3 pancakes then.

What I said before about P(X+1) <= P(X)+2 still holds.

oooh, he’s just making it up as goes along! :)

Reply Quote

Date: 31/12/2013 22:40:50
From: mollwollfumble
ID: 462028
Subject: re: Pancake Numbers

The Rev Dodgson said:


oooh, he’s just making it up as goes along! :)

Too right. I now have a lower limit on pancake numbers.
P(4) = 4
P(5) >= 4
P(10) >= 9
P(20) >= 16
P(30) >= 24
Those are based on the maximum number of permutations than can be generated by N flips of X pancakes.

Reply Quote

Date: 31/12/2013 22:43:28
From: mollwollfumble
ID: 462029
Subject: re: Pancake Numbers

Of course, from the original post we already know that P(20) >= 22.

Reply Quote

Date: 31/12/2013 23:09:53
From: Wocky
ID: 462030
Subject: re: Pancake Numbers

mollwollfumble said:


The Rev Dodgson said:

oooh, he’s just making it up as goes along! :)

Too right. I now have a lower limit on pancake numbers.
P(4) = 4
P(5) >= 4
P(10) >= 9
P(20) >= 16
P(30) >= 24
Those are based on the maximum number of permutations than can be generated by N flips of X pancakes.

I get:
P(4) = 4
P(5) = 5
P(10) = 11
21 <= P(20) <= 32
32 <= P(30) <= 49

But I may be wrong.

Reply Quote

Date: 1/01/2014 09:42:34
From: Soso
ID: 462099
Subject: re: Pancake Numbers

mollwollfumble said:


If P(X) is the number of flips required for X pancakes, it is easy to prove that P(X+1) <= P(X) + 2, for all X.

Since it takes 0, 1 or 2 flips to move the largest pancake to the bottom being the reasoning?

mollwollfumble said:


It’s also trivial to prove that if any two pancakes in a stack of X pancakes is initially in either the correct order or the reverse of the correct order then P(X) <= P(X-1)+1

What’s your reasoning here? I initially assumed the same thing, that an pre-ordered pair could be treated like a single pancake, but realised the sorting process might reverse the order of the pair, and it would take 3 flips to to correct that at the end.

Reply Quote

Date: 1/01/2014 10:24:29
From: mollwollfumble
ID: 462115
Subject: re: Pancake Numbers

Wocky said:


mollwollfumble said:

I now have a lower limit on pancake numbers.
P(4) = 4
P(5) >= 4
P(10) >= 9
P(20) >= 16
P(30) >= 24
Those are based on the maximum number of permutations than can be generated by N flips of X pancakes.

I get:
P(4) = 4
P(5) = 5
P(10) = 11
21 <= P(20) <= 32
32 <= P(30) <= 49
But I may be wrong.

You’re better than me. Overnight I figured out that, because each pancake flip can bring only two adjacent pancakes together, and because in the original stack for X>2 it is always possible to have no two finally-adjacent pancakes initially-together, P(X) >= X-1 for all X.

Somewhat annoying, but potentially useful, is that flipping 3412 to get a final 1234 requires four flips. Not only does 3412 contain two finally-adjacent pancakes but it also cannot be obtained by inserting a single pancake anywhere in the stack 213. The stack 213 is the only stack of three pancakes that requires three flips to get 123. That makes it more difficult to get P(X) from P(X-1).

I can see three possible approaches to calculating P(20) by computer, none seems to be particularly easy.

1. Run it like a “sieve of Eratosthenes”. Starting from all the pancakes in final order 1 2 3 … 20 perform pancake flips in turn until all possible permutations are covered. The problem with that is that storing all possible permutations (20!) requires at least 17*4*20! bits of data. That’s 41 million terrabytes of data, too big. As more flips are done but before 20 are done, this can be used to slowly raise the minimum value of P(20). Hold on, perhaps I can reduce that to 20! bits of data, 600 petabytes of data, still too big.

2. Choose a “random” starting permutation from a set of “difficult ones” and calculate how many permutations are needed to create it. This is very much slower than the first approach unless the set of “difficult ones” can be reduced to something small, and I don’t see how it can be. This gives a very rapid calculation of a lower limit on P(20). A lower limit on P(X) obtained this way will usually be the actual value of P(X), but proving that for any given X would be very difficult.

3. Working from P(19) insert an unknown size “y” pancake into the stack and reproduce the flips on that stack as if it had 19 pancakes, with “y” remaining unknown. After the flips the pancake “y” will be in a specific position (actually two or more positions as the method bifocates) and that position suffices (ie. two or more positions suffice) to determine the value (values) of “y”. This finds all permutations of 20 pancakes that can be flipped in the same number of flips as 19 pancakes. This approach is slower than the first approach and faster than the second approach, except that it still doesn’t decide between P(20) = P(19) +1 and P(20) = P(19) + 2.

Reply Quote

Date: 2/01/2014 16:30:49
From: mollwollfumble
ID: 462851
Subject: re: Pancake Numbers

> P(X) >= X-1 for all X.

P(X) > X for all X.

Reply Quote

Date: 2/01/2014 16:42:06
From: Wocky
ID: 462864
Subject: re: Pancake Numbers

mollwollfumble said:


> P(X) >= X-1 for all X.

P(X) > X for all X.

The first one was right. Consider,

P(1) = 0
P(2) = 1
P(3) = 3
etc

Reply Quote