Page 1 of 1

Puzzles

Posted: Wed Oct 27, 2010 1:56 pm
by Usge
This is a puzzle/question offered up as an example of the kind of logic problems a software engineer might run into.

There are 3 boxes of fruit: 1 of apples only, 1 of oranges only, and 1 of apples and oranges mixed. Each box is mislabed as to it's contents. Pick one piece of fruit, from one box only, then solve what is in each/all box from that result. Detail the solution in such a way that you can solve it had your result from picking the one piece of fruit been the opposite result (ie., an orange instead of an apple). Again, you are starting by picking one piece of fruit, from one box...not one from each box. And you can't see/sense what's inside the box. Only what piece of fruit you pull out.

We had fun with it at the bar....using our shot glasses to visualize the problem, etc.

Re: Puzzles

Posted: Wed Oct 27, 2010 2:16 pm
by kiwistiller
Bastard. I'll be thinking of that all day now.

Edit, got it now... won't ruin it for others though!

Re: Puzzles

Posted: Wed Oct 27, 2010 4:48 pm
by father william
This is a puzzle/question offered up as an example of the kind of logic problems a software engineer might run into.
Sounds like the kind of logic problem a green grocer might run into to me.


Here's one they ask prospective new hires at MicroSoft:

Why are manholes circular?

Re: Puzzles

Posted: Wed Oct 27, 2010 5:19 pm
by loneswinger
Ok, I give up. Maybe I am the sucker but I don't see how it could be done aside from trick answers like how they smell, their dent patterns or such.

So I just pulled an orange from box 1, what are the contents of all the boxes? I have 4 possibilities on paper. You tell me which is correct.

Back at you. Or Kiwi since you know the answer also.

-Loneswinger

The man-hole one is pretty clear.

Re: Puzzles

Posted: Wed Oct 27, 2010 6:07 pm
by kiwistiller
you haven't given enough info, loneswinger. what was the label on the box you pulled the orange out of?

Re: Puzzles

Posted: Wed Oct 27, 2010 6:17 pm
by Dnderhead
got it but it only works if they all are marked wrong..and you knew this.

Re: Puzzles

Posted: Wed Oct 27, 2010 6:21 pm
by still crazy
ditto on what dunder said

Re: Puzzles

Posted: Wed Oct 27, 2010 6:21 pm
by ScottishBoy
Juice them all and ferment...then who the fuck cares?

Re: Puzzles

Posted: Wed Oct 27, 2010 6:46 pm
by Husker
if all boxes are mislabled, then this is a trivlal problem. I have not read past the first reply (of kiwi). But it is trivial. I can answer it now, but will look to see if anyone has posted answer prior

I will rot13 post it though :)

fryrpg n sehvg sebz gur obk ynoryrq zvkrq. Vs vg vf nccyr, gura gur benatr vf va gur obk znexrq nccyr, naq zvkrq vf va obk znexrq benatr.

Vs gur sehvg cvpxrq sebz zvkrq vf nccyr, gura guvf bar vf nccyr, gur bar znexrq zvkrq vf benatr naq bar znexrq benatr vf zvkrq.

H.

Edit a rot13 convert page is here: http://personal-computer-tutor.com/rot13.htm" onclick="window.open(this.href);return false;" rel="nofollow

Edit, I screwed up the 2nd part. It should have started if the 'other' type fruit was selected (then reverse results). I think I listed the same pick twice. But I am leaving the rot13 alone.

Re: Puzzles

Posted: Wed Oct 27, 2010 6:51 pm
by Kentucky shinner
why did the chicken cross the road :?:
now theres a stumper :lol: :lol: :lol:

Re: Puzzles

Posted: Wed Oct 27, 2010 6:55 pm
by Husker
Kentucky shinner wrote:why did the chicken cross the road :?:
now theres a stumper :lol: :lol: :lol:
About 20 years ago, while driving with my (then) young kids, we figured that question out, when it happened right in front of us. The chicken crosses the road to get to the corn field. We were stopped on the edge of town (grand island NE) by a flock of chickens crossing the road to get to the corn field :)

H.

Re: Puzzles

Posted: Wed Oct 27, 2010 6:57 pm
by Kentucky shinner
Now we all know... Thanks Husker :ewink:

Re: Puzzles

Posted: Thu Oct 28, 2010 9:06 am
by Usge
You are right Husker...the solution is simple...but understanding the problem is what initially tripped us up when we were trying to find it. Once the parameters are in place and understood...and properly visualized, the solution came pretty quickly:

Solution:
You always start with the box labeled "mixed fruit". Since it's "mislabeled", whatever fruit you pick from it..(apple or orange) has to be either all apples or all oranges. So, now you know that either all apples or all oranges is in the mixed fruit box. We'll solve this for both.

If the fruit you picked from mixed box was an apple then the mixed box contains all apples:
There are 2 mislabed boxes left to solve (all apples and all oranges) and to determine which fruit (oranges or mixed fruit) is in which one. Since the oranges cannot be in the all orange box (it's mislabed), then it has to be in the all apples box. That means the mixed fruit is in the all orange box.

If the fruit you picked from mixed box was an orange then the mixed box contains all oranges:
The apples are in the all orange box. And the mixed fruit is in the all apple box.

There was another simple logic problem/puzzle that a friend presented....in that it represented how to save money/time, etc..for search algorithms. He never gave the solution, and I didn't solve it, but here's the puzzle (I'm sure some somebody out there already knows it)

You have 7 straws. They all weigh exactly the same...except for 'one' straw which is slightly heavier. You could obviously weigh each one and average them to find the heavy one. But, the problem presented was to find the heavy straw in just 2 moves/procedures.

Re: Puzzles

Posted: Thu Oct 28, 2010 9:53 am
by loneswinger
kiwistiller wrote:you haven't given enough info, loneswinger. what was the label on the box you pulled the orange out of?
Oh sorry. Box 1 was labeled "Yams", Box 2 was labeled "frozen peas", and Box 3 was labeled "nuclear waste". :D

Even if 'mislabeled' as in still labeled orange, apple, orange/apple, you couldn't do it arbitrarily. You would have to pull from a particular box to get a definitive answer every time. Maybe that was the question, what box do you pull from?

-Loneswinger

Re: Puzzles

Posted: Thu Oct 28, 2010 10:01 am
by loneswinger
Usge wrote: You have 7 straws. They all weigh exactly the same...except for 'one' straw which is slightly heavier. You could obviously weigh each one and average them to find the heavy one. But, the problem presented was to find the heavy straw in just 2 moves/procedures.
Always hard to define two-moves. You could put 3 on one side of a balance, 3 on the other. If it balances, it is the odd straw not on the balance. If it doesn't balance, you take the 3 straws from the heavy side, then put 1 on one side of the balance, then one on the other, and same logic applies. If that is considered "two moves" then it is solved.

-Loneswinger

Re: Puzzles

Posted: Thu Oct 28, 2010 10:49 am
by ScottishBoy
Kentucky shinner wrote:why did the chicken cross the road :?:
Because it was Carbon Arc welded to the robot!

Re: Puzzles

Posted: Thu Oct 28, 2010 11:16 am
by Usge
loneswinger wrote:
Usge wrote: You have 7 straws. They all weigh exactly the same...except for 'one' straw which is slightly heavier. You could obviously weigh each one and average them to find the heavy one. But, the problem presented was to find the heavy straw in just 2 moves/procedures.
Always hard to define two-moves. You could put 3 on one side of a balance, 3 on the other. If it balances, it is the odd straw not on the balance. If it doesn't balance, you take the 3 straws from the heavy side, then put 1 on one side of the balance, then one on the other, and same logic applies. If that is considered "two moves" then it is solved.

-Loneswinger
That sounds good to me Loneswinger :)

Re: Puzzles

Posted: Thu Oct 28, 2010 4:32 pm
by blanikdog
ScottishBoy wrote:Juice them all and ferment...then who the fuck cares?
:lol: :lol: :lol: :lol: :lol:

Re: Puzzles

Posted: Thu Oct 28, 2010 7:48 pm
by Husker
loneswinger wrote:
Usge wrote: You have 7 straws. They all weigh exactly the same...except for 'one' straw which is slightly heavier. You could obviously weigh each one and average them to find the heavy one. But, the problem presented was to find the heavy straw in just 2 moves/procedures.
Always hard to define two-moves. You could put 3 on one side of a balance, 3 on the other. If it balances, it is the odd straw not on the balance. If it doesn't balance, you take the 3 straws from the heavy side, then put 1 on one side of the balance, then one on the other, and same logic applies. If that is considered "two moves" then it is solved.

-Loneswinger
That is the answer. It is a 'modified' binary search type algorithm (divide and conquer) . One out of 7 times it can be done in 1 step. The other 6 out of 7 times requires 2 steps.

H.

Re: Puzzles

Posted: Fri Oct 29, 2010 7:05 am
by rad14701
Husker is right... Those of us who program know that with a binary search on a sorted data set will have to be sampled a maximum of 8 times in order to find the record you are searching for... Dropping the record count below 8 records (straws) reduces the maximum sampling iterations required, sorted or not... Just boring computer geek crap to most, I'm sure...

Re: Puzzles

Posted: Fri Oct 29, 2010 7:46 am
by Husker
Instead of a binary search, this is actually a ternary search (3 vs 2), but it is the same thought process. It is ternary, since there is 3 groupings that one of them is picked from, and continued from there. For a binary search, the set is divided into 2 groups, and one group is selected, and the process is repeated over and over, until only 1 item is uniquely identified.

In a binary search, the working set is cut in half (rounded down) each step. In the ternary search, the working data is cut into 1/3 (rounded down).

The same puzzle could find the 1 heavy straw, out of 9 straws in 2 steps. The puzzle is done the way that it is, so that it is harder to 'see' the method needed. If it was an even 9, then the triple divide and conquer is easier for some people to see (or have that 'ah-ha' moment). Starting from 7 straws makes 'the obvious' a little less obvious. If it was 9 straws with 1 heavy, it would always take 2 steps.

H.

PS, often times it sux to be a computer nerd, and to actually think using these forms of logic. I find it much harder to actually explain to others, than it is to actually build the logic needed, into a rigid procedural language. English flows in a way that is not conducive to writing logic.

Re: Puzzles

Posted: Fri Oct 29, 2010 2:42 pm
by Usge
Not a binary type, but we had fun toying with it over beer/drinks. :ewink:

Re: Puzzles

Posted: Fri Oct 29, 2010 4:48 pm
by MuleKicker
Husker wrote:Instead of a binary search, this is actually a ternary search (3 vs 2), but it is the same thought process. It is ternary, since there is 3 groupings that one of them is picked from, and continued from there. For a binary search, the set is divided into 2 groups, and one group is selected, and the process is repeated over and over, until only 1 item is uniquely identified.

In a binary search, the working set is cut in half (rounded down) each step. In the ternary search, the working data is cut into 1/3 (rounded down).

The same puzzle could find the 1 heavy straw, out of 9 straws in 2 steps. The puzzle is done the way that it is, so that it is harder to 'see' the method needed. If it was an even 9, then the triple divide and conquer is easier for some people to see (or have that 'ah-ha' moment). Starting from 7 straws makes 'the obvious' a little less obvious. If it was 9 straws with 1 heavy, it would always take 2 steps.

H.

PS, often times it sux to be a computer nerd, and to actually think using these forms of logic. I find it much harder to actually explain to others, than it is to actually build the logic needed, into a rigid procedural language. English flows in a way that is not conducive to writing logic.
What the hell? Im lost...... :oops:
Screw it, Im goin to my girlfriends house to check my wash. 8)

Re: Puzzles

Posted: Fri Oct 29, 2010 4:51 pm
by MuleKicker
ScottishBoy wrote:
Kentucky shinner wrote:why did the chicken cross the road :?:
Because it was Carbon Arc welded to the robot!
umm, you dumbass, you cant weld a chicken. :lol: