A farmer has a 40-pound rock that he uses with a balance-type scale to measure grains and feed. He lends that rock to a neighbor, and the neighbor accidently breaks the rock. It is broken into four pieces. He returns the rocks to the farmer and is very apologetic. The farmer, unexpectedly, is pleased. He says with these four pieces of rock and the balance-scale that he can now measure everything from 1 to 40 pounds. What is the weight of each rock?
I know that some of the team know the answer (or at least remember the riddle). But the answer doesn’t really matter. Here is the challenge: Using Ruby (or some other programming language), write a script that tests your guess.
As a bonus, write an algorithm that derives all the possible combinations of stone weights.
Bonus points for elegant code.
Bragger’s rights for the first good script.