You are on your way to visit your Grandma, who lives at the end of the valley. It's her birthday, and you want to give her the cakes you've made.

Between your house and her house, you have to cross 7 bridges, and as it goes in the land of make believe, there is a troll under every bridge! Each troll, quite rightly, insists that you pay a troll toll. Before you can cross their bridge, you have to give them half of the cakes you are carrying, but as they are kind trolls, they each give you back a single cake.

How many cakes do you have to leave home with to make sure that you arrive at Grandma's with exactly 2 cakes?

EDIT : If you go to your grandma's with a half eaten cake, she's gonna be pissed. The trolls can't give you half a cake back. It is unhygienic and disgusting.

  • 3
    $\begingroup$ Can you pay toll with less than whole cakes? For example, if you leave the house with one cake will you pay half a cake toll to the first troll? $\endgroup$ – Nit Jun 8 '14 at 23:34
  • 4
    $\begingroup$ @Nit and will he then give you one cake back, so you end up with 1.5 cakes? $\endgroup$ – wchargin Jun 9 '14 at 0:56
  • 21
    $\begingroup$ @Nit Then you could go back home, put half a cake in the fridge, and repeat. Infinite cakes! Trolling the trolls? $\endgroup$ – wchargin Jun 9 '14 at 15:46
  • 5
    $\begingroup$ @Nit: not that I think the question really needs the hair-splitting, but it says that the transaction occurs before you can cross the bridge, not before you do cross it. So I don't think it's entirely clear whether you can walk up to the first bridge with 0 cakes, give the troll 0 cakes, receive one cake in return, then run away, put the cake down (cakes you are not "carrying" are tax-exempt), repeat, pick up both cakes and proceed ;-) $\endgroup$ – user1501 Jun 9 '14 at 18:47
  • 19
    $\begingroup$ What this puzzle fails to point out is that you will be trapped beyond Grandma's house forever if you let her eat your cake. Thus proving you can't have your cake and eat it too. $\endgroup$ – Zibbobz Oct 8 '14 at 19:06

If you leave home with

2 cakes, you will never pay the troll toll. You give him half of your cakes (one) and he gives one cake back to you.

So the answer is


The exact solution :

Assume we have $x$ cakes,

- after the 1st bridge, we have $\frac{x}{2}+1 = \frac{x+2}{2}$ cakes
- after the 2nd bridge, we have $\dfrac{\frac{x+2}{2}+2}{2} = \dfrac{x+2+4}{4}$ cakes
- after the 3rd bridge, we have $\dfrac{\frac{x+2+4}{4}+2}{2} = \dfrac{x+2+4+8}{8}$ cakes - ...
- after the nth bridge, we have $\frac{x+2+4+\dots+2^n}{2^n}$ cakes
- So, after the last bridge ($n=7$), we have $\frac{x+2+4+8+16+32+64+128}{128} = \frac{x+254}{128}$ cakes

According to the puzzle, we have

2 cakes at the end,


$$ \frac{x+254}{128} = 2 \\\implies \boxed{x = 2}$$


The answer is 2.

  • 9
    $\begingroup$ This proves that you CAN have 2 cakes when you leave home. But this doesn't prove that you HAVE to have 2 cakes when you leave home. $\endgroup$ – klm123 Jun 8 '14 at 10:41
  • $\begingroup$ @klm123 - you can now see the solution if you want. $\endgroup$ – Alireza Fallah Jun 8 '14 at 11:40
  • $\begingroup$ you still have a hole in your prove (usual induction doesn't prove anything), but I guess it doesn't matter, this is for author to decide. Sorry for my nicety. $\endgroup$ – klm123 Jun 8 '14 at 11:52
  • 1
    $\begingroup$ if you start with less then two cakes, you'll never get two cakes. that really doesn't need proving $\endgroup$ – greg m Jun 8 '14 at 16:53
  • 3
    $\begingroup$ You can generalize this to any number of trolls/cakes pretty easily by noting that $2 + 4 + \dots + 2^n = 2^{n+1}-2$ $\endgroup$ – BlueRaja - Danny Pflughoeft Jun 9 '14 at 21:46

The above answers are correct in a sense, but unfortunately incomplete. There are three scenarios:

1) The trolls round down. That is, if you had 3 cakes, they take floor(1.5) = 1 cake from you. In this case, you may leave home with, at minimum, zero (0) cakes.

Why? Consider each troll as below (the item number is the troll toll number):

  1. Takes 1/2 of your cakes (which is 0), and gives you 1. Now you have 1 cake.
  2. Takes 1/2 of your cakes (which is floor(0.5) = 0), and gives you 1. Now you have 2 cakes.
  3. (and all other trolls following) Takes 1/2 of your cakes (which is 1), and gives you 1. Now you have 2 cakes.

Thus, you may start with a minimum of 0 cakes, and end up with 2 at the end of the route.

2) The trolls round up. This is a nearly identical process, so I will neglect the explanation. In this case, you must leave home with a minimum of 2 cakes and a maximum of 255 cakes.

2) The trolls don't round, and deal with floating point numbers: I don't really want to think about this case... :) I believe that a starting value of 2 is minimal, but do not have time to prove so.

  • 6
    $\begingroup$ If the trolls take fractional cakes, it's not hard to show that leaving home with 2 cakes is the only solution. (Just start from the known number of cakes at the end and work backwards; without rounding, there's a one-to-one correspondence between the number of cakes carried before and after each t(r)oll.) $\endgroup$ – Ilmari Karonen Jun 9 '14 at 8:02
  • 35
    $\begingroup$ I really like the idea of the trolls going "Aww, you don't have any cake? Here, have one of mine!" $\endgroup$ – Bobson Jun 9 '14 at 14:45
  • 16
    $\begingroup$ If the troll rounds down, you can start with a debt of 125 cakes. The first troll takes half of your -125 cakes, -62.5, rounded down (up in negative): -63, you keep -145 - -63 = -62, you receive one, you have -61. With 7 bridges, it will go: -125 -> -61 -> -29 -> -13 -> -5 -> -1 -> 1 -> 2. $\endgroup$ – Florian F Sep 25 '14 at 14:35
  • 4
    $\begingroup$ Well, I thought of 125 notes saying "IOU 1 cake". And if you want to do a reality check you'll have just as much trouble finding trolls on bridges than to represent negative cakes. $\endgroup$ – Florian F Oct 2 '14 at 11:55
  • 3
    $\begingroup$ Well hold on now, if the trolls round their tolls down, you'll end up with 3 cakes if you start with any more than 2. $\endgroup$ – Joe Z. Oct 16 '14 at 14:03

(presses the rewind button on reality)

You leave grandma's house with two cakes. Each time you cross a bridge, you give the troll one cake, and then he gives you back a number of cakes equal to how many you have left.

It's easy to see that every time you leave a bridge, and thus when you return home, you still have two cakes.

  • 2
    $\begingroup$ How is this answer different from already posted ones? $\endgroup$ – kaine Jun 9 '14 at 19:30
  • 4
    $\begingroup$ @kaine: Presentation. And no solving is needed to obtain the answer. $\endgroup$ – user1502 Jun 9 '14 at 20:32
  • 3
    $\begingroup$ @Hyrkyl no solving is needed for the first part of the accepted answer. It just goes into more detail to prove itself. $\endgroup$ – kaine Jun 9 '14 at 20:35
  • 4
    $\begingroup$ I'm not harassing and I'm not the one who downvoted you. Just was hoping to understand what was being contributed by what I saw as a duplicate answer. I won't ask anymore. $\endgroup$ – kaine Jun 9 '14 at 20:44
  • 2
    $\begingroup$ (oh and you showed up in my review becasue it was your first post and I explictly did not want to downvote) $\endgroup$ – kaine Jun 9 '14 at 20:50

This problem is really too easy, since a moment's reflection (or reading any of the previous answers) shows that travellers with 2 cakes can cross any bridge keeping all their cakes. To make it more interesting, one may generalise to what would be needed at departure if one wants to have 3 cakes (or any other number$~n$) at arrival. I'll assume cakes cannot be subdivided, and that although kind, these are real world trolls that won't let you pass taking any less than half of your cakes (before returning one), so that (like for parking meters) if you ain't got exact change for what you want, you must pay a bit more.

The only point I want to make is that this kind of problems becomes very easy working backwards. If you need$~n$ cakes after passing a bridge, one of those will be returned from the troll, and to have the remaining $n-1$ after paying the troll, you need to have had at least $2(n-1)$ before the bridge. So to cross $k$ bridges and have$~n$ you need to iterate $k$ times the operation $f: n\mapsto2(n-1)$ with starting value$~n$. For instance to cross 7 bridges and have 3 cakes left you need to start out with at least $f(f(f(f(f(f(f(3)))))))=130$ cakes.

There is a nice formula for the result once you realise that $f(2+m)=2+2m$ for all non negative integers $m$, but that is not my main point.


It depends how you define half of cakes, for example for 3 cakes. Assuming round up:

3 cakes -> half is 2 -> leaves 1 -> +1 back -> you have 2 cakes
4 cakes -> half is 2 -> leaves 2 -> +1 back -> you have 3 cakes
5 -> 3
6 -> 4
7 -> 4
8 -> 5
.. and so on

Theoretically every number between 2 and N should work, figuring out the highest possible number N is left as homework exercise. ;)

Hint, for every number x, the highest one leading directly to it is 2x-1.


Answer is 2.

Prove is the following:

If you have 2 cakes after last troll and X cakes after previous troll then 2=(X/2+1) and X = 2.

The same we conclude that number of cakes after each troll wasn't changed.

That means you left with 2 cakes.

  • 1
    $\begingroup$ Calculation is clearer if you say: x/2+1=2, so x=(2-1)*2, so x=2. $\endgroup$ – TFuto Jun 8 '14 at 20:15

Any solution that is longer than three lines, not including any smug prefaces about other solutions, is overdoing things.

Start from the back: You want to reach grandma with two cakes, so you were left with one before the last troll gave you one. Thus, you reached that troll with two cakes. Thus, we find that reaching a troll with two cakes does the trick. And we extrapolate.

If we were to answer the question of finding every solution, on the other hand...


It depends on how forgiving your grandma is when you present her with fractional cakes. If she accepts 1.99 cakes as being the same as 2 cakes, then you can start with 1 cake (because [1+254]/128>1.99). If she accepts 1.98 cakes as being the same as 2 cakes, you can start with 0 cakes (because [0+254]/128>1.98).

  • 2
    $\begingroup$ No doubts that 1.99 is not "exactly 2 cakes". $\endgroup$ – klm123 Jun 9 '14 at 9:03
  • 5
    $\begingroup$ but it is interesting that if there were an infinite number of trolls, this would work. $\endgroup$ – kaine Jun 9 '14 at 12:47
  • 3
    $\begingroup$ @kaine but then you'd never be able to get to grandma's house. :P $\endgroup$ – Justin Jun 12 '14 at 17:33
  • 5
    $\begingroup$ Only if your name is Zeno. $\endgroup$ – Florian F Sep 25 '14 at 14:38

The minimum number of cakes is

2, no matter how many bridges there are.

because with

2 cakes you have to give one of them away and will get another as a reward. then you can cross further bridges infinitely.

  • 4
    $\begingroup$ This doesn't offer more than what the existing answers do... $\endgroup$ – Assafi Cohen-Arazi Nov 5 '17 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.