# Wednesday, December 12, 2007

Bar of Gold

Bar of Gold is a fairly simple word problem I give people I interview for technical positions. It's not huge think question, IMHO. It's really designed to see if you can conjure a thought process. And while there are, I'm sure high fa luting ways to solve it, a straight forward brute force attack and you can't help but solve it. The most common response I get from candidates is to stare intently at the white board and make a face like that makes me hope their are wearing and adult diaper. The most successful candidates at this just start solving the problem out loud and quickly realize that by beginning to solve it you pretty much can't help but solve it. I know this, because I was presented this problem in an interview with a much higher value and I managed to solve it.

Here is the problem:

You have 1 bar of gold and 7 days of work to be done. You hire a man to do the work for you and agree to pay him 1/7th of your bar of gold a day. You must pay him in full at the end of every day. The problem is you can only cut the bar of gold in two places. Where do you make the two cuts in the bar of gold so that you can pay him properly each day?

Additional Info: Since you live in such a remote location the guy doesn't have any where to spend any of the money you pay him from day to day and because you don't provide your employees with lockers he carries all his gold on him.

My feeling is if you start to solve the problem using trial and error you'll come across the solution pretty quickly. If you stare at it, you invite an aneurysm.

Now the funny part. I had to write this down somewhere. A while back we did a mass intern interview where the candidates showed up anytime from 10 AM to 3 PM and during that window we would try and get them seen by at least 2 interviewers. The thing about intern interviews is that you can't really expect the students to have specific technical expertise, you're looking for good foundations in Computer Science and problem solving and communication abilities. That's why I like the bar of gold. You have to have problem solving abilities and explain to me how you arrived at the solution.

Well, there was one candidate who was exceptionally nervous to whom I gave this problem. He looked as if is head was going to explode until I repeated the question about 5 times clarifying the problem. He then proceeded to scribble down the following formula and then look up at me half triumphantly and half in uncertainty and more or less remarked, "there."

[ 1 - [ 1 - ( 1 - Δ 1/7) 1/7 ] 1/7 ]

There what? How did you arrive at this conclusion and what is the answer? Nothing. And while I'm not sure what that formula expresses, I'm reasonably confident it's not the answer.

In case you can't figure it out I'll leave the answer in the comments in a few days.

Answer posted in the comments 12/16/2007

Wednesday, December 12, 2007 10:38:41 AM (Eastern Standard Time, UTC-05:00)
#    Comments [1] |
Monday, December 17, 2007 3:11:35 PM (Eastern Standard Time, UTC-05:00)
Sarah, you got it correct.

As I said before, if you start to solve it more or less breaks open. Let's just walk it through:

End of Day 1 - you must pay him 1/7th of the bar of gold. The only viable option is to cut the bar into two pieces that are 1/7th and 6/7ths.

End of Day 2 - He has 1/7th of a bar of gold and you have 6/7ths. Now you could cut again cut off 1/7th yielding two pieces that are 5/7ths and 1/7th of the original bar, but that puts you in a really bad spot for day 3. So let's rule that out. Now, he has to be paid 2/7ths, and we've ruled out slicing off another 1/7th. So that leads us to the other option, swap him the 1/7th he has for the 2/7ths he requires.

So, you cut the remaining 6/7ths of the bar into two pieces one that is 2/7ths and 4/7ths. Give him the piece that is 2/7ths and take back the 1/7th piece. He now has the 2/7ths he supposed to.

End of Day 3 - He has one piece that is 2/7ths and you have two pieces that are 1/7th and 4/7ths. You simply hand him the piece that is 1/7th.

End of Day 4 - you essentially repeat what you did on day two. Take back the 1/7th and 2/7ths pieces and give him the 4/7th piece.

End of Day 5 - Give him the 1/7th piece.
End of Day 6 - Take back the 1/7th piece and give him the 2/7ths piece. He should now be holding two pieces 4/7ths and 2/7ths.
End of Day 7 - Give him the final 1/7th piece.

So in short, the answer is cut at 1 and 3 thereby creating three pieces 1/7th and 2/7ths and 4/7ths.
Comments are closed.