You are on your way to visit your grandma, and you have to cross seven bridges, each with a troll under them. You want to give your grandma two cakes. Whenever you cross a bridge, you must pay the troll half of your cakes. As he is nice, he will give you back one cake.
How many cakes should you head out of the house with?
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.
The problem stated you would need 2 cakes for grandma. Nothing has been said about having exactly 0 cakes after giving 2 cakes to her.
This is the solution I ended up using. I tried to start at the first troll with a number like 100. Then soon ran into odd numbers. I tried 128. That didn't work either. Then I tried started at the last troll and soon realized, that in order to end up with 2 cakes, the last troll would have given 1 cake back to go from 1 to 2. But he took half of them to go from 2 to 1.
Log in to reply
but if you start with none and he already has a cake...
Log in to reply
You cannot start with none because the 6th troll gave you a cake... so you must have at least a cake
Log in to reply
@Ernesto Civello – I am sorry but aren't we all thinking of her journey forward?what of her return
Log in to reply
@Nehemiah Osei – She must have 258 cakes. This way when she gets to the final troll, she has 6 cakes. He takes half and gives her one. She now has 4. Gives jer
grandma 2 and can return with the other two
@Ernesto Civello – they all give you a cake
That's also the solution i had used..it took me time to realize it.
if i am understand u q (transltion) in last brigde u need 6 because 6/2=3 and -1=2 then and in 6 bridge u need 12 and >>>>>* to 5ridge u need 24 >>>*> then last 243 or more
if you don't want a troll to eat you, they better get something each time and not figure out any trick before the last bridge as they may text the next troll. So take enough to give each at least half your cakes (nobody wants crumbs) to each troll and so that each gets something. I think you would have 128-65- 33-17-9-5-3-2. The trolls get 63-32-16-8-4-2-1 which is a difference of 2. Everbody happy!
ughhh! I can't find a comment to say.
Mathematical way of doing the problem.
Let N r be the number of cakes I have after crossing r bridges.
N 0 = x N 1 = 2 x + 2 N 2 = 4 x + 6
Similarly,
N r = 2 r x − 2 + 2 r + 1 .
Therefore,
N 7 = 1 2 8 x + 2 5 4
Given N 7 = 2
x + 2 5 4 = 2 5 6 x = 2 .
Therefore, I must carry 2 cakes.
If you take half a cake, you will get almost 2 cakes after crossing all 7 bridges. The less you take, the more cake you will get.
Unless you have to give the troll whole cakes.
Log in to reply
Read the problem again. Trolls take HALF OF YOUR CAKES..
The troll can't give you back cakes you haven't given him...
If I take no-cakes, and the troll will give me a cake after I pay half of my cakes, then I still end up with cake...
Log in to reply
You gave nothing, so are you sure that the troll will let you go?
Log in to reply
@Cedric Magno – I paid half of my cakes! That's the only condition...
Yes, but you need to end up with two.
Try again. You are to end up with two cakes, not "almost" two cakes.
awesome answer sadi
in numerator it should be 2^(r+1)
I can not waste any cake,so I must take 2 cakes so that each time I give half of it(1) to the troll,no. of cakes remains the same, when he gives me one back.
2/2=1(I give half) 1+1=2(he gives one back) It remains the same.
Upvote please!!!!!!!!!
This solution is incomplete. How would you know that the answer is only 2 and no other value satisfy the condition?
I think he meant working backwards
Not sure that the questions calls for a distinct answer.
3/2-1=.5,I lose .5
See my answer below.
(Going backwards in time)
28) I give grandma
2
cakes, after leaving Troll
7
with them
27) Troll
7
gives back to me
1
cake
26) I had
1
cake after Troll
7
took half of what I had
25) Troll
7
takes
1
cake from me, half of the
2
I had
24) I left Troll
6
carrying
2
cakes....
23)...(repeat)
Hence, there is no other solution other than to start the trip with 2 cakes.
backtracking is the most optimal way to solve this.
at 7th bridge after giving away half of what u had...u r left with 2 cakes
at 6th bridge suppose u have x cakes x/2 +1 = no. of cakes at the 7th bridge...here
x=2...hence 2 cakes at the 6 th bridge too
at 5 th bridge , say u have x cakes again x/2 +1= no .of cakes at 6 th bridge x/2+1 =2 .x=2 ; ; . ; similarly 2 cakes at every bridge results in 2 cakes at the end
You need 2. But on your way home, you get 1 cake after the first bridge, then 1.5 after the second bridge, then 1 3/4 after the third, then 1 7/8 after the fourth, etc. If there were countably infinite bridges to cross, you'd get back home with 2 cakes. (As it is, you only have 1 and 255/256ths cakes.)
You also get a quite interesting sequence of numbers if you want to give your grandmother 3 cakes. I'll leave that for the reader, though.
You only need two cakes; all the trolls are a bit thick! (or just too generous!)
Let's he started with A cakes. So, After the first Bridge, he left with {A-A/2 +1} = {(A + 2)/1} After Second Bridge = (A+6) /4 After third Bridge = (A+14/8) So, we can see a pattern after crossing each Bridge= {(A + 2^ (n+1) - 2) / 2} where n is no. of bridges. so after 7 th Bridge, he should have 2 cakes. solve the equation you will get the answer
We need 2 cakes in the end, let the total no. of cakes be x, and we have 7 trolls which divide our no. of cakes by 2 and give one back, this implies the equation ((((((x/2 +1)/2 +1)/2 +1)/2 +1)/2+1)/2+1)/2+1= 2 Every time we subtract 1 from RHS we also multiply by 2, which gives us the final answer 2
This troll isn't greedy at all!
Since he'll give you back 1 of your cakes whenever you cross a bridge, and you give him a 1/2 of all your cakes when you cross a bridge, you should bring 2. It' basic logic.
1st Troll : 1 cake given, 1 cake received
You can repeat this with the next 6 trolls
Or, you could put poison in the cakes :)
Array yar ......every Indian solve this.
2 because when ever you give him half of your cakes he will give you a one back then your cakes are going to stay 2 for ever
Well every troll takes half of your cakes and gives u one more. So let's look at the last troll. How much cakes u need in order to have 2 cakes remaining? The answer is 2.... yeah have two and none of the trolls can have any net effect on ur number of cakes cuz they are so nice that if u havetwo cakes they give back what they took. So there it is- just go with two cakes and troll the trolls.
We know that in the end we will have two cakes. We go backwards. We give the troll back his one cake he gave us out of niceness(-1). The troll gives us back half our cakes he took from us (Now we have 2 times the amount as before. Hence times 2). Repeat 6 more times. This can be written in a programmable for loop in any programming language.
x=2
for (i=0; i<7; i++)
- x=(x-1)*2
Another solution is a recursive function:
x=number of cakes we want to give grandma
y=number of bridges we have to cross
f (x, y) will be defined as followed:
If y=0 we have reached grandma so f (x,0) will be x
Otherwise we call the function again with following parameters: f ((x-1)*2, y-1)
So for the start we have f (2,7)=f ((2-1)*2, 7-1) And so on.
To solve this problem I thought backwards.
To have 2 cakes after crossing the last troll (#7!), how many cakes should I be carrying? The answer was 2: if I arrive with 2 cakes, I have to give him half of them (=1), and he gives me back 1 cake. This made me realize that, by going backwards, if I had two cakes with each troll I'd always keep all two of them.
working backwards, when you cross back to the 7th bridge, you subtract one cake:1, and then multiply that by two, so 2. it repeats so you need to start with 2 cakes.
Since it is half a cake, and the troll has to give you a full cake, you will get 2 cakes after crossing the bridge all 7 times. You start with half a cake , and then you get 1 cake back, so now you got 1 cake. Give half of that cake to troll on the next bridge, you would have 1.5 of a cake. Next bridge you would have 2. and so on and so on. The less cakes you take the more cakes you shall end up with. 2/2+1 is the equation.
Problem Loading...
Note Loading...
Set Loading...
It is best to start with the last troll. If you need 2 cakes for grandma, and he gives you back 1, then 1/2 of the cakes = 1 cake, so you should get to the last troll with 2 cakes.
You can repeat this with the other 6 trolls to find that you only need 2 cakes to start with.
Here is how you can check your work mathematics:
With 2 cakes,
Troll 1: 2 ÷ 2 + 1 = 2
Troll 2: 2 ÷ 2 + 1 = 2
Troll 3: 2 ÷ 2 + 1 = 2
Troll 4: 2 ÷ 2 + 1 = 2
Troll 5: 2 ÷ 2 + 1 = 2
Troll 6: 2 ÷ 2 + 1 = 2
Troll 7: 2 ÷ 2 + 1 = 2
And you have your 2 cakes left for granny!