programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# fruit problem

Anupam Sinha
Ranch Hand
Posts: 1090
This is a question that I read far back when I was a kid. Before I give the question the words strictly means what they should. Example may and will are two different words. The question is : A person is assigned a task of labeling baskets of fruits namely Apples, Oranges and Apples and Orange. That is a basket contains Apples, another Oranges and another one Apples and Oranges. Now the person puts the label all wrong. Now you will have to tell which basket contains which fruit just by putting your hand in two baskets and taking out one fruit from each basket and relabel the labels correctly.

Jim Yingst
Wanderer
Sheriff
Posts: 18671
Ummm... why would we need two hands? One pick from a basket is enough...

Michael Morris
Ranch Hand
Posts: 3451
Originally posted by Jim Yingst:
Ummm... why would we need two hands? One pick from a basket is enough...

Some of us are ambidextrous Jimbo.

Anupam Sinha
Ranch Hand
Posts: 1090
Originally posted by Jim Yingst:
Ummm... why would we need two hands? One pick from a basket is enough...

Would really like to know how can this be done with just one pick.

Michael Morris
Ranch Hand
Posts: 3451
Two questions:
1. When you say all wrong do you mean that none of the baskets have the correct label?
2. If we fire the dufus that f---ed it up in the first place do we have to pay him unemployment?

Michael Morris
Ranch Hand
Posts: 3451
Assuming that all three labels are wrong here's the solution:
Pull from the basket marked Apples. If you pull an apple then it should be labled Apples/Oranges, then pull from either of the other baskets and whatever fruit you pull there is how it should be labeled and the third is whatever is left over.
If you pull an Orange from the basket labeled Apples then pull from the basket marked Apples/Oranges. If it is an Orange label it Orange, label the one currently labeled Apples as Apples/Oranges and label the third one Apples. If it is an Apple, label it Apples, label the one marked Apples as Oranges and label the last one Apples/Oranges.

Anupam Sinha
Ranch Hand
Posts: 1090
Hi Michael
Yes Michael all three labels were wrongs and your answer is correct.

Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
One hand solutuion:
Pull from the basket marked "apples/oranges"...
And Jim should be able to tell the fruits without touching them at all! Otherwise, it's too easy for him.
[ June 27, 2003: Message edited by: Mapraputa Is ]

Arjun Shastry
Ranch Hand
Posts: 1906
1
Pull the fruit from any basket,Suppose from Apples/Oranges,and you get apples,it contains apples.the one which is labelled 'Oranges' contains Apples and Oranges and one labelled Apples contains Oranges.

Anupam Sinha
Ranch Hand
Posts: 1090
Hi Capablanca
Your point is good. Never really though about that, but that would only work if the first basket you try is labeled Apples & Oranges.
[ June 27, 2003: Message edited by: Anupam Sinha ]

Richard Scothern
Ranch Hand
Posts: 83
Originally posted by Michael Morris:
Assuming that all three labels are wrong here's the solution:
Pull from the basket marked Apples. If you pull an apple then it should be labled Apples/Oranges, then pull from either of the other baskets and whatever fruit you pull there is how it should be labeled and the third is whatever is left over.
If you pull an Orange from the basket labeled Apples then pull from the basket marked Apples/Oranges. If it is an Orange label it Orange, label the one currently labeled Apples as Apples/Oranges and label the third one Apples. If it is an Apple, label it Apples, label the one marked Apples as Oranges and label the last one Apples/Oranges.

Actually the baskets can be labelled from picking just one fruit from the apples/oranges basket. The original challenge of using two picks is incorrect.

Arjun Shastry
Ranch Hand
Posts: 1906
1
OK, I thought we can pickup from any basket.and I chose A and O basket with minimum pick.

Michael Morris
Ranch Hand
Posts: 3451
The original challenge of using two picks is incorrect.
Who says? That was the problem as stated. If someone one gives you the option of having more material to complete a task than is necessary do you turn it down?

Jim Yingst
Wanderer
Sheriff
Posts: 18671
It's not incorrect, but it is unnecessary. In case you want to keep one of your hands free for something else, Michael.

Anupam Sinha
Ranch Hand
Posts: 1090
The two picks were an option because they were the given options to me. What's wrong with them, if you solve it with just one pick great otherwise two pick is atmost what you are allowed to do. Secondly Capablanca your answer was great, I just did not think about it and I guess Jim also had the same answer. Sorry for not mentioning Map's answer. He was also amongst the first one to point out that only one pick may do the trick.
Pull the fruit from any basket,Suppose from Apples/Oranges,and you get apples,it contains apples.

Edited because of Jim's post.
The word any may suggest that any basket can be chosen so I guess it should be Apples and Oranges basket should be chosen instead of any.
[ June 27, 2003: Message edited by: Anupam Sinha ]

Michael Morris
Ranch Hand
Posts: 3451
Originally posted by Jim Yingst:
It's not incorrect, but it is unnecessary. In case you want to keep one of your hands free for something else, Michael.

Actually, the one hand solution is simpler, DOH. If I have a bad character flaw, it has to do with attacking a problem from a more complex level than is necessary. The boolean algebra is more complicated with the two hand solution than the one hand. I didn't consider a one-hand solution. You only have two simple statements to contend with using the one hand approach.

Jim Yingst
Wanderer
Sheriff
Posts: 18671
I guess Jim also had the same answer.
Yep. And don't forget Map, who was the first one to specify that picking from the apple/orange basket is the key.
Pull the fruit from any basket,Suppose from Apples/Oranges,and you get apples,it contains apples.

For your answer to work the word any should not be there.

Well I disagree, but I guess this is a language interpretation issue. If someone says to me "pull fruit from any basket" that implies to me that I can choose any basket I want to. If they say pull fruit from this basket" or "pull fruit from one particular basket which will be selected randomly", that would be different.

Jim Yingst
Wanderer
Sheriff
Posts: 18671
If I have a bad character flaw
Oh, sure, try to limit the list to just one... :roll:

Anupam Sinha
Ranch Hand
Posts: 1090
Hi Jim
Agreed, Jim. Changing my post because of that. Sorry for not mentioning Map's answer doing that as well. But I do agree with Map that you shouldn't be allowed to touch, as that's too easy for you.

Jim Yingst
Wanderer
Sheriff
Posts: 18671
Hey, I didn't actually specify the answer - I let Map do that.
But just to be nice, I will withold my answer to " not using any loops" for now.

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.