Tuesday, July 08, 2008

My math is not that rusty yet =)

My math and problem analytic skill are not that rusty yet. This is proven by what happened today. So, in short, Chatrin sent an email about a math problem.
Egg $0.10
Chicken $6
Watermelon $3

Question:
How many of above items to get the total 100 items of $100 dollar?
OR If from software point of view, how to calculate it by algorithm?
If you are not interested in knowing how it is solved, it doesn't matter. The answer is
70 eggs, 10 chicken, and 1 watermelon

This is the algorithm that I derived. I eliminate the basic steps so you can find it out yourselves.
For w=0 till w=31
.... c=(900-29w)/59
.... if c is a positive integer then
.... .... e = 100 - c - w
.... ....if e is a positive integer, then
.... .... .... return value of e, c, w (solved)
.... .... .... endif
.... endif
end for
return false (cannot be solved)
w = watermelons, e = eggs, c = chicken.

My math is not that rusty yet, hahaha....

Labels: ,


Comments:
Not 100 items?
 
How about:
70 eggs ($7), 1 chicken ($6), and 29 watermelon ($87) ?
100 items for $100
 
Eggs will be in 10s since we do not want cents (cents will not add up with $6 chickens and $3 watermelons to make $100)

e=10
while e <= 100
for c=1; c<=(100-e-1); c++
for w=1; w<=(100-e-c); w++
if (c+w==(100-e)) &&
(6c+3w==(100-0.1e)) then
finish
e=e+10
loop
 
Diana,
I screwed up...
The total of the items is not 100. After flying so much, your maths is not that rusty yet =).

Felrick,
Yeah... way to go! A cool optimization you did there. Used to do that when I was still active in Topcoder community.
 
Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Comments [Atom]