# How many cookies does someone need to grab to be certain to obtain a flavor?

I often found this riddle in many exams but I got often confused on how to tackle it. While it involves maths. I wonder if there is a subtle or a more layman method to obtain an answer using common sense?.

The problem which I'm about to describe isn't a specific homework problem. Is just a situation which I had imagined just now based on the kind of situation which often gets me confused. Okay here it goes:

A toddler want to grab some strawberry cookies. However there are three flavors of those cookies in a jar, which just happen to be atop of a refrigerator. There is a ladder in the kitchen, but the height of that ladder isn't bigger enough for him to tell the difference between which flavor of the cookies is which, all he can do is extend his arm and take out the cookies from the jar. The child knows from his mom that she made 10 of those strawberry cookies in the morning. However he knows that the jar also has leftovers which he spotted on the night before and these were 6 of vanilla flavor and 5 of chocolate chips.

Okay now comes the part where I often got stuck at:

What is the least amount of cookies that he has to take out from the jar to be certain that he has 4 of chocolate chips, 5 of vanilla and 7 of of strawberries?.

Now a second question

What is the least amount that he has to take out to be certain that he has all the strawberries and all chocolate chips?

And finally the third one

What is the least amount that he has to take from the jar to be certain that he has 1 of each flavor.

What I do remember from this situation is that when solving this riddle you often consider the most difficult scenario, in other words. He needs to take out let's say 10 in this case so with that he is certain that has strawberries. However I'm not very sure if this reasoning is valid.

Can somebody give me some help with this?

I'm slow at catching up ideas so, I'd like the answer could show or include the most details as possible and explain why certain decision or argument is taken.

• Okay, a few things. 1: if the cookies were made this morning, they are very likely on top of the other cookies within the jar, so the selection should be trivial. 2: Since when do toddlers take less than all of the cookies? Commented Mar 25, 2019 at 13:29
• Has a useful answer been given? If so, please don't forget to $\color{green}{\checkmark \small\text{Accept}}$ it :)
– Rubio
Commented Mar 27, 2019 at 20:01
• @IanMacDonald As I mentioned in the beginning this was a thought problem not likely a real scenario. But what might be missing is assuming that the kid would take less than all the cookies. Another aspect is also assuming that during the handling of the jar to be put back atop the fridge there might be some shacking and the cookies would be mixed altogether. Hence making sort of draw of lots. Commented Mar 27, 2019 at 20:41
• @Rubio Thanks for the reminder, actually there are some unattended questions which I provided to the lonely answerer. I'm awaiting his response. Commented Mar 27, 2019 at 21:03
• A toddler has small hands, so, to take more than one cookie, he will have to do it one at a time. True, he does not know what he is taking, but he does know what he has picked up. Therefore, it will stop taking when he has what he wants, and that means that the worst scenario is a possibility of answer, but it is not even the most probable. He could be lucky, and catch just the cookies he wants the first time, or at least not have bad luck and not fall into the worst scenario. Commented May 22, 2019 at 10:24

Originally there are;

10 S, 6 V and 5C

For the first case where he wants to have 7 S, 5 V and , 4 C. (so we dont want to have 3S, 1V and 1C)

In the worst case scenario;

we need to think that he is very unlucky, while taking out cookies, he takes all strawberries first, where there are 10 of them, so extra 3 cookies, and etc.

so

He has to take out 10S+6V+4C = 20 cookies to guarantee he can have 7S, 5V and 4C. Put the extras back later.

I do not want to continue for the rest since the same methodology works for them too:

in the worst case scenario, take out first the type of cookie which has the most extras (number of cookies available - wanted amount of cookies), then second most and lastly the least one.

This will give you the number of cookies to guarantee to have some specific number of cookies.

• I understood the part that he has to take all the 10 S. Then 6V as by this time he has ensured that has those 7S and 5V. Then in the jar the remaining cookies are just C. So he only has to take out 4C. Is this the reasoning correct?. In other words it would be meaningless if he wanted 3V or 4V in the end he would need to take out all of the vanilla cookies?. This is the part where I'm still stuck. If I understood correctly. The second situation is more extreme as I presume he has to take all the cookies from the jar to ensure he has all the S and all C., right? Commented Mar 27, 2019 at 20:57
• and finally for the third situation, it would be 10S+6V+1C or 17 cookies. Am I right?.As I mentioned I'm slow at catching up so I need some clarification about this. I was some confused about what you wrote on so we dont want to have 3S, 1V and 1C as I did not know what to do with those numbers, summing them to 7S, 5V and 4C or subtracting them from the quantities mentioned?. To coincide with what you wrote it seemed to me that I needed to sum the first two to the initial 7S and 5V and add the last one to get the answer. Maybe can you add some explanation of how you used those numbers? Commented Mar 27, 2019 at 21:02
• Sorry, but mind if you take a look at some unattended questions?. I'm still stuck to know if what I wrote in the above comments are alright or not?. Commented Mar 31, 2019 at 5:46
• you are right, it would be 10S+6V+1C for the last case, you got it right. the idea is simply to take them maximum number of cookies which will not satisfy the condition until it will be indifference whichever cookie you will take one more or in other word, with the worst case scenario to guarantee to hold the condition.
– Oray
Commented Mar 31, 2019 at 6:57
• Where @Oray says "we don't want to have 3S, 1V and 1C", think of it as "we want to leave behind in the jar 3S, 1V and 1C". Commented May 21, 2019 at 18:55

Let's start by answering a simpler question: what's the minimum number of cookies he needs to take in order to be sure he has at least one strawberry cookie?

We can figure this out by looking at the worst possible case. If our boy is extremely unlucky...

...the first five cookies he pulls out might all be chocolate chip, and the next six might be all vanilla. So eleven is not enough. But once he's taken those eleven cookies, all the remaining ones will be strawberry, so his twelfth cookie is guaranteed to be strawberry if none of the other nine were. Thus, the answer is twelve.

Now for the third question (where we want at least one of each flavor),

He can use the same logic as above to figure out how many cookies he needs to take to guarantee at least one chocolate chip (17) and how many he needs to guarantee at least one vanilla (16). After the twelfth cookie he has at least one strawberry; after the sixteenth cookie he now also has at least one vanilla, but only after seventeen cookies is he guaranteed to have at least one chocolate chip as well. So the answer is seventeen.

Now we can also address the first question, which is similar, except that he needs more than one of each kind of cookie (4 chocolate chip, 5 vanilla, 7 strawberry).

We know that if he draws twelve cookies, he'll be guaranteed to have at least one strawberry cookie. If his first eleven cookies were all non-strawberry, then the remaining ones in the jar can only be strawberry cookies. So the after taking thirteen cookies, he's guaranteed to have at least two strawberry. And so on: after taking fourteen, he must have at least three strawberries, and after eighteen cookies, he must have at least seven of them.

Likewise,

After twenty cookies he must have at least four chocolate chip, and after twenty cookies he must have at least five vanilla. Since he already had enough strawberry ones back at eighteen, by twenty cookies he'll have enough of all three flavors.

Finally, for the second question, in order to be certain that he has all the strawberries and all the chocolate chips:

He has to take all the cookies. If he even leaves one cookie behind, that one could be a strawberry or chocolate chip one. There are twenty-one cookies altogether, so that's how many he has to take.

As an aside: if our toddler can figure all of that out for himself, I suspect he's probably unusually bright for his age. He might be able to figure out how to bake his own cookies.