Logic Puzzle: Jelly Beans

Hope this one is a little harder then the last one.  Please keep in mind that all comments will remain hidden until I post the answer to allow others to try to solve it.

Puzzle

You work at a factory that creates bags of jelly beans.  You make three types of bags, one that is all green, one that is all red, and one that is a mix of red and green.  Someone walks into your office this morning and tells you that the bags are labeled wrong.  Now you cannot see through the bags to see the contents, your fellow employee asks you to figure out which are which.  But there is a catch.  Opening a bag costs money and so they want to label them all correctly with opening the fewest amount of bags.  Also, touching or pulling out a jelly bean also costs money as it is contaminated.   So they want you to do it looking at the fewest amount of jelly beans as well.  (No, you can't just peek inside a bag)

How many bags do you need to open and how many jelly beans do you need to look at?  What would you do?

Published 27 August 08 06:00 by Tom
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Matt said on August 27, 2008 7:03 AM:

Now I know that I may be being too literal, but if

"You make three types of bags, one that is all green, one that is all red, and one that is a mix of red and green."

Then I'd just look at the colours of the bags...

Failing that, if the bags were consistenly wrong (i,e, all reds green, all greens mixed, then the answer is 2 bags.)

# brad.covell said on August 27, 2008 10:26 AM:

2 bags, 2 jelly beans from each bag

# Mikkel said on August 27, 2008 11:25 AM:

:o9

Assume bags R,G and M

we know M to be mislabelled, so the kind of bean in M is known to be either green or red. Open M and take one bean from it.

a) the bean is Red. So M should be R. We know G and R to be mislabelled to start with, so logically switching labels M and R is not enough to restore order to the label chaos. That is:

M -> R,

R -> G,

G -> M

b) the bean is Green. So M should be G etc. like in a)

M -> G,

G -> R,

R -> M

So one bag and one bean will suffice

If we don't know that all bags are mislabelled (ie. only Mixed and Red labels were switched), then we need to open a few more bags.

again:

Open M and take N/2+1 beans.

a)it's mixed: open G. take 1 bean.

b) it's not mixed: open G take N/2+1 beans

by now you know what is in bags labelled M and G. rearrange labels accordingly.

a) happens 1/3 of the times b) happens 2/3.. so on average you'd need to open 2 bags and take (N/2+2 + 2(N+2))/3 = 5N/6+2 beans

... asuming all bags are mislabelled consistently or put in separate piles with same content

# Justin said on August 27, 2008 11:29 AM:

1 bag 1 Bean

Open mix bag. All bags are all labeled wrong so it has to be incorrect.

Take out one jelly bean

Swap all labels that say mixed to that colour label.

Then swap all labels of the opposite colour to mixed.

# John Hensley said on August 27, 2008 3:35 PM:

If all bags with common labels contain the same types of jelly beans and all of the bags are incorrectly labeled you would only need to open one bag marked mixed and remove one jelly bean from it to determine what all of the other bags in the factory contain.

If the jelly bean is green then bags labeled mixed contain green, bags labeled green contain red and bags labeled red contain mixed.

If the jelly bean is red then then bags labeled mixed contain red, bags labeled red contain green and bags labeled green contain mixed.

# Tony A said on August 27, 2008 4:29 PM:

This is going on a few assumptions:

- All bags have the same number of beans (N)

- The mixed bag has an equal number of red & green beans (N/2)

To definitively identify the contents of a bag, we need to pull (N/2+1) beans.  If it's a green bag, then they'll all be green; if it's a red bag, they'll all be red; and if it's a mixed bag, there will be at least one bean of each colour pulled (since there's only N/2 beans of each colour).

To match the 3 mislabeled bags to their correct labels, we only need to open 2 bags.  This will leave one bag left over, and only one possibility for what's inside it.

This seems a little naive though... I'm hoping to find a trickier solution :)

If you want to reduce the number of beans pulled, you could make a probability-based argument, I suspect.

# sudeepg said on August 27, 2008 6:36 PM:

I'd first open the bag that's Mix or labelled so. Since we are told that bags are labelled incorrectly, if I get Green (let's assume), then the bag labelled Mix actually contains Green jelly beans.

Now, without opening other 2 bags... we can decipher that the bag labelled Green cannot contain Green jelly beans because we already found it. Also, the bag labelled red cannot be red because they are labelled incorrectly. Therefore the bag labelled Green contains Red jelly beans and the bag labelled Red contains the mix of green and red jelly beans. We can then label them appropriately.

# Seema said on August 28, 2008 7:16 AM:

Answer is 1

Open the bag labelled 'Mixed'

if the bean is red, then

         bag labeled red will be 'green'

         bag labelled green will be 'Mixed'

if the bean is green, then

         bag labelled green will be 'red'

         bag labelled red will be 'Mixed'

cheers,

seemaDOTnairATliveDOTcom

# Ed said on August 28, 2008 12:15 PM:

One. If all bags are labeled wrong, open the bag labeled Mix.  Select the bag with the color of the jelly bean you chose (red or green) and rename it to the opposing color. Then rename the last bag to "Mix"

Wait, I've confused myself :)

# James said on August 28, 2008 3:18 PM:

Here is my try, not sure if it's correct.

Get three bags with all different labels.

Start by removing one bean out of two bags.  If they are the same color you know the third bag is not the mix and is the opposite color.  If they are different remove a bean from the third bag, the one with a different color is not the mix and you know the color.

The two bags remaining is difficult, you may have to keep removing beans until you come across one with a different color.  So in the best case you remove 2 beans, in the worst half the bag.

To answer:

Best Case, open two bags, remove two beans from each.

Worst Case, open three bags, remove one bean from one, and remove half the beans from the other two.

# ASP.NET Debugging said on August 29, 2008 11:06 AM:

So this is the answer to the logic puzzle that was posted here . The fewest amount of bags that you can

# ASP.NET Debugging said on August 29, 2008 11:07 AM:

So this is the answer to the logic puzzle that was posted here . The fewest amount of bags that you can

# William said on August 29, 2008 4:12 PM:

Some people are assuming that ALL the bags are mislabeled.

IMO

(the bags are labeled wrong) <> all bags mislabeled

ex:

r -> b

b -> r

m -> m

# Hanan said on August 31, 2008 3:44 AM:

As William points out it's an assumption that all the labels are incorrect and that all the labels ended up on the same type of bag, ie. all mixed bags are labeled green. We also can't assume that a mixed bag has the same amount of each color, I've never seen a bag of MM's with the same number of each color. I believe the only quantitative answer possible is all the jelly beans from all the bags.

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Page view tracker