Hacker News new | ask | show | jobs
by e271828 4254 days ago
There is a geometric way to solve this, requiring only graph paper and a straight edge.

If x is the number of chickens sold in the morning, and y is the number sold after lunch, then the straight line x+y=10 represents all possible values of x and y for the first farmer. Of course, this allows fractional chickens, so the true set of possible values is the set of points where x and y have integer values.

Now you can draw parallel lines to this first line for x+y=16 and x+y=26, representing valid x and y values for the second and third farmer.

Now, if you take any other line that intersects these 3 lines, then that line can be represented by the equation ax+by=35, for some value of a and b. The key observation then is that if we interpret a and b as the morning and afternoon prices respectively, then the points where this line intersects each of the 3 parallel lines represents the x and y values for each farmer such that that farmer's net earnings are $35.

So now the problem reduces to placing a straight edge on your paper and finding a line that passes through integer points on each of the 3 parallels.

This is pretty easy - start with the edge at (0,26) for farmer 3 and (1,15) for farmer 2 and see if it intersects the first line at an integer point - it doesn't. Keep going and you'll find a nice intersection at (0,26), (5,11) and (8,2). Unfortunately the corresponding prices don't round nicely to cents, but you can shift the entire line to the right to get the right answer: (1,25), (6,10) and (9,1), corresponding to prices of $3.75 and $1.25.

1 comments

This solution got me thinking about something which I found interesting enough to feel the need to share.

I can imagine my Dad using this geometric method to solve the problem at hand. He's a very intelligent guy who has worked in the building industry doing manual labor all of his life.

I can guess that my sister, who is a medical doctor, would have solved it using the same process as the (current) top rated response here; stepping through the equations.

My immediate response would be to hack up a script and brute force the answer.

My Mother would tell me to go ask Dad.