At a party with 100 people, there is a pie. The first guest gets 1% of the pie, the second gets 2% of what is left, the third gets 3% of what is left and so on.
If the n th guest gets the largest piece of all 100, what is n ?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Edit: f ( n ) = 1 0 0 n i = 0 ∏ n − 1 1 0 0 1 0 0 − i
Couldn't have said it better myself!
Technically the maximum is between 9 and 10, so you would need to check both possibilities and see which one is higher. This is straightforward using the formula f ( n ) = 1 0 0 n n ! ( n − 1 9 9 )
Log in to reply
I don't think you need to check both. The fact that the solution is approximately 9.5 (not an integer) means that the ratio f ( n + 1 ) / f ( n ) is never equal to 1. This means it is either < 1 oder > 1 . This translates into the fact that there is only one maximum value. Since it is precisely > 1 when n ≤ 9 , this means the maximum is at n = 1 0 .
Log in to reply
Ah, I see that I was wrong about checking both cases. I was thinking in terms of f ( n + d n ) / f ( n ) > 1 (i.e. continuous) instead of f ( n + 1 ) / f ( n ) > 1 (i.e. discrete). I was incorrectly associating f ( n + 1 ) / f ( n ) > 1 with a positive continuous slope instead of a positive discrete slope.
I have this habit of making exactly three mistakes on my way to finding a solution, so I didn't get the chance to share my solution. I plotted the function f(n)=n*((99!/(100-n)!))/(100^n), and although it isn't nearly as beautiful or simple as your solution (and is a lot more circuitous than just plotting a recursive function), I haven't seen it mentioned yet.
Log in to reply
well Jose Fernandez Goycoolea (see below) made a plot too). But he did not post it as a solution....
Log in to reply
It was less the plot I was talking about, and more the use of this type of function.
I did something similar, but I was observing when is f(n+1) - f(n) > 0. This leads to the same quadratic equation, which again gives n=9, so f(10) > f(9), and this n is the biggest such that f(n+1)-f(n) is true.
Log in to reply
Yes, the two ideas are equivalent (as long as f ( n ) > 0 ): f ( n ) f ( n + 1 ) > 1 ⟺ f ( n + 1 ) > f ( n ) ⟺ f ( n + 1 ) − f ( n ) > 0 so it's normal that you get to the same equation. I don't know why I chose my starting point (rather than yours), it's a question of taste I suppose...
Just a question please.. the answer of course is 10 with a piece size around “6.281565”. I know it is not 2π exactly... but it is close to that. Is that just a coincidence? Thanks
Log in to reply
For the 2 π , I'm pretty sure it's a coincidence. But it might depend on how you wish to extend the problem when there are more than 100 persons.
Here would be my choice: you have N persons; the 1st gets N 1 of the pie, the 2nd N 2 of what remains, etc...
The solutions goes as above with
N
in place of 100. The person with the biggest chunk will be (unless
1
+
4
N
is an integer)
n
N
=
⌊
2
1
+
4
N
−
1
⌋
+
1
. The size of his chunk will be given by evaluating
f
(
n
)
=
N
n
i
=
0
∏
n
−
1
N
N
−
i
at
n
N
.
Now the values of f ( n N ) → 0 . What is interesting is that f ( n N ) ≈ N 0 . 6 0 6 5 3 0 6 . . . . I think the 0 . 6 0 6 5 3 0 6 . . . should be e − 1 / 2 , but I just checked it numerically.
You can try to prove it! ... or ask this as a question to the community.
Hint: Note that the easiest case is N = 1 0 2 k then n N = 1 0 k and so N ⋅ f ( n N ) = i = 0 ∏ 1 0 k − 1 1 − 1 0 2 k i More generally for N large, N ⋅ f ( n N ) = ∏ i = 0 N − 1 1 − N i
TLDR I think this is related to e but not to π , but you only see this if you go far out in the sequence.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
1 |
|
note that you can terminate the search early
1 2 3 4 5 6 7 8 9 10 11 |
|
whats the time and space complexity of your solution to the problem?
Log in to reply
Storage space is constant, i.e. O(1). Time is linear, i.e. O(N). The loop is continued all the way to p=100.
In principle this code would work for any arbitrary sharing function, and it could be optimized to terminate when the remainder of the cake is less than the biggest piece, which in this case would occur at p=23, which would make it a bit faster. For this "linear" sharing function, as mentioned below, it is quite easy to show that the search can be terminated when the size of the pieces starts to decrease (at p=11).
This looks like cheating! XD
Let f ( n ) be the fraction of the pie n t h person gets. Let 1 denote the amount of pie in the starting.
So, f ( n ) = 1 0 0 n ( 1 − i = 1 ∑ n − 1 f ( i ) ) for n ≥ 2 … Eq. 1
Also, f ( n ) = i = 1 ∑ n f ( i ) − i = 1 ∑ n − 1 f ( i ) … Eq. 2 .
Using Eq. 1 in Eq. 2 , we get
f ( n ) = 1 0 0 ( n f ( n ) − n + 1 f ( n + 1 ) ) ⇒ f ( n ) f ( n + 1 ) = 1 0 0 n ( 1 0 0 − n ) ( n + 1 )
Now we have to find maximum value of n such that f ( n + 1 ) ≥ f ( n ) i . e . f ( n ) f ( n + 1 ) ≥ 1
⇒ 1 0 0 n ( 1 0 0 − n ) ( n + 1 ) ≥ 1 ⇒ ( 1 0 0 − n ) ( n + 1 ) ≥ 1 0 0 n ⇒ n 2 + n − 1 0 0 ≤ 0
The positive root of this equation ≈ 9 . 5 1 . So maximum value of n can be 9 .
And so, f ( 1 0 ) ≥ f ( 9 ) . Hence 1 0 th person will get the largest piece of pie.
You didn't write the base case for the above defined recursive function. f(1) = 0.01
I got lazy at deriving formula, so I used excel.
Column A as guest number, Column B (amount of pie) and C (pie remaining) with formulas as shown, and dragged the them down all the way to 100th guest, and plotted graph, to reach answer -->10
Bashed with a calculator. Trivial.
Dang, I wish I was as good as you.
Math meme comment. Trivial as well.
When it is the turn of number m, a certain part, 'r', of the pie is left.
Person number m gets 'r' multiplied by (m/ 100), i.e.
= r*(m/100)
which is the formula for m per cent of 'r', and the amount of pie left is
= r *(100-m)/100.
When it comes to the turn of the next person m + 1, he will get
= r* ((100-m)/100)* ((m+1)/ 100).
Therefore person m+1 gets more than person m, if
(100-m)/100)* ((m + 1)/100) > m/100.
This reduced to the inequality
100 - m- m^2 > 0 ,
is true for m = 1, 2...., up to 9.
In other words, the amount of pie taken by each person keeps on increasing until the 9th person , but from the 10th person and beyond the amount is smaller.
Therefore, we conclude , number 10 gets the largest amount.
This above solution is discussed for the same puzzle which appeared recently in Guardian paper.
Some Haskell code. (Type annotations omitted for space and not needed since Haskell has type inference).
1 2 3 4 5 6 7 8 |
|
1 |
|
Let f ( j ) be the fraction of the pie received by the j th person. Then we have f ( j ) = g ( j ) h ( j ) , where
g ( j ) h ( j ) = i = 1 ∏ j − 1 ( 1 − 1 0 0 j ) = 1 0 0 j
Let Δ denote the finite difference operator. Then Δ f ( j ) = g ( j ) Δ h ( j ) + Δ g ( j ) h ( j + 1 ) . Since Δ h ( j ) = 1 0 0 1 and
Δ g ( j ) = g ( j + 1 ) − g ( j ) = g ( j ) ( 1 − 1 0 0 j − 1 ) = − 1 0 0 j g ( j ) ,
we have that g ( j ) Δ h ( j ) + Δ g ( j ) h ( j + 1 ) = 1 0 0 1 g ( j ) − 1 0 0 j 1 0 0 j + 1 g ( j ) = [ 1 0 0 1 − 1 0 0 0 0 j 2 + j ] g ( j )
Since g ( j ) is positive, we have [ 1 0 0 1 − 1 0 0 0 0 j 2 + j ] g ( j ) > 0 when 1 0 0 1 > 1 0 0 0 0 j 2 + j , or equivalently 1 > 1 0 0 j 2 + j , or equivalently 1 0 0 > j 2 + j . When j is restricted to be an integer, this happens precisely when j < 1 0 , so j = 1 0 is the first integer at which Δ f is decreasing. This tells us immediately that n = 1 0 , since all values of f ( j ) with j < 1 0 are smaller since f is increasing on them and all values of f ( j ) with j > 1 0 are smaller since f is decreasing on them.
i uh... just wrote a matlab code... is that cheating?
pie(1)=100;
for i=1:100
cut(i)=i/100;
cutofpie(i)=pie(i)*cut(i);
pie(i+1)=pie(i)-cutofpie(i);
end
max(cutofpie) %now look in the variable cutofpie for the entry at which the max value is in.
I did exactly the same :)
If we simplify the problem and think about ten guest, who's proportions increase by 10% instead of 1% of what's left, calculate how much each of those gets and plot it, we get the brown function. Its maxima is at around 30% so the third guest gets the biggest part.
When we decrease the percentage to 5% (red line) and in the end to 1%, we see that the maxima shifts, as more stuff is taken from the cake in the beginning and therefore sooner less is left. Therefore the maxima, where the percentage is big enough to get more than the person before, but the cake is still large enough to not outweigh the increase in percentage, is shifted to the left. To about 10%. That is why the tenth person gets the most cake with 0,628% of the total cake.
THIS "big" piece of cake would leave me still hungry ;)
I used Excel, set up the following way: ||Guest #||Share||Pie Remaining|| ||1||=A2 A2/100||=1-B2|| ||2||=(C2 A3/100)||=C2-B3|| ... ||100||=(C100*A101/100)||=C100-B101|| |
Graphing can also be used to solve this problem.
Let f ( x ) = n = 1 ∏ x 1 − 1 0 0 n
A plot of this function:
Source: https://www.desmos.com/calculator/w8o7mdfuc2
Let j ( x ) = f ( x − 1 ) − f ( x )
The function j ( x ) shows the difference between two consecutive values. The peak of the graph of the function j ( x ) shows the number of the guest that took the largest piece of the pie.
The plot of the function
j
(
x
)
=
f
(
x
−
1
)
−
f
(
x
)
:
Source: https://www.desmos.com/calculator/w8o7mdfuc2
The peak of the graph is at 1 0 and thus the 1 0 th person is the one who took the largest piece of the pie. The answer is 1 0 .
NOTE: Both function are not continuous and that is why they are "cut" between each whole number.
Here's a wicked and intuitive way to figure out this problem!
Consider the following as if it were a new problem:
1. For the first few n , each slice of pie will be just slightly less than n % of the pie in size.
2. The size of each slice of pie will only start to decrease when half the pie has been eaten.
Given this, how many slices do we eat before half the pie is gone?
For complicated reasons, the simplified logic of the new problem illustrated here holds when applied to the main problem. Good luck!
We can model the amount of pie left after x people take their share with a recursive function:
f(x) = f(x-1) - f(x-1)*(x/100), f(0) = 1.
This can be simplified to this:
f(x) = (f(x-1)(100-x))/100
If we extend this function out, evaluating it at f(1),f(2), etc., then you notice a pattern develops:
f(x) = (99!/(100-x)!)*(1/100^(x+1))
If you want to find out how much x person takes, simply multiply the amount of pie by the persons number over 100:
f(x) = 99!/((100-x)!*100^x)
Plugging this into desmos (I know this is cheating), the maximum is at x=10.
Notice that 2nd person gets bigger piece of pie than 1st and so on, until n+1th person gets smaller amount of pie than n-th. Let's naively set up an equation where two consecutive people get equal amounts: first of them gets p of the (remaining) pie, and second (p+0.01)(1-p) of it. p = p - p^2 + 0.01 - 0.01p which yields p = 0.095. It's easy to check that 10th person gets more than 9th (11th) person.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
1 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
1 2 |
|
Here is an Excel solution:
Let’s assume this pie has a total amount of 100. The actual unit doesn’t matter.
In cells A1 through A100, enter numbers 1 through 100. Column A represents n.
In cell B1, enter: =(A1/100)*100
In cell B2, enter: =(A2/100)*(100-SUM($B$1:B1))
Copy cell B2 and paste into cells B3 through B100. Column B represents the amount of pie the corresponding nth person will get.
You will find that at n=10, the amount in cell B10 is the highest at 6.2816. This means the 10th person, or n = 10, gets the most pie.
Problem Loading...
Note Loading...
Set Loading...
Let f ( n ) be the fraction of the pie the n th person gets. Then f ( n ) = 1 0 0 n i = 0 ∏ n − 1 1 0 0 1 0 0 − i
Consider f ( n ) f ( n + 1 ) = 1 0 0 1 0 0 − n ⋅ n n + 1 Then f ( n ) f ( n + 1 ) > 1 if and only if 1 0 0 1 0 0 − n ⋅ n n + 1 > 1 ⟺ ( 1 0 0 − n ) ( n + 1 ) > 1 0 0 n ⟺ 1 0 0 − n − n 2 > 0 Now one root of the polynomial 1 0 0 − n − n 2 is negative while the other is ≈ 9 . 5 1 2 . This means the ratio f ( n ) f ( n + 1 ) > 1 as long as n ≤ 9 . So f ( n ) is increasing until it reaches n = 1 0 . After that it decreases.
Thus the 1 0 th person gets the largest part of the pie.