gee...
oh well.
fish for $203.02 each
Cacti for $301.09 each
and Apples for $107.04 each
I spend $2752.57 at the store.
how many items of each did i buy?
Ok, if i break the prices down into hundreds, ones and cents, and assume there is no overflow then.
If F is the number of fish that I buy, C is the number of Cacti, A is number of apples, then I can say that:
2*F + 3*C + 1*A = 27.
3*F + 1*C + 7*A = 52.
2*F + 9*C + 4*A = 57.
which you can solve however you like, I solved it as a matrix equation:
| 2 3 1 | | F | = | 27 |
| 3 1 7 | | C | = | 52 |
| 2 9 4 | | A | = | 57 |
(trying to draw matrices on this forum sucks!)
yeilding F = 7, C = 3, A = 4.
I kind of expected someone to see that. oh well.
leads me to wonder if this method could be generalized, perhaps even to the xkcd question...
Ok, so just some stream of consciousness math,
how could this kind of problem be solved analytically?
here is an idea:
lets assume that I can buy fractions of each item, ie. that the solutions can belong to the real numbers.
so if the there are 3 kinds of items that I can buy, and their sum must add to certain X, then the solutions space for the problem must be 2-dimensional.
lets assign an analytic function f(p, a) such that for each point on 3D space p and parameter a, as limit a -> infinity, then f(p, a) = 1 if and only if point p belongs to the solution space, otherwise zero.
if we have another analytic function g(p, b) such that as b-> infinity then it converges to the 3D dirac comb (such that each peak lies on respective whole numbers - and peaks exist only in the positive quadrant).
if we take f times g and multiply it by some kind of normalizing function, and then take a and b to infinity, then we should be left with a function equivilant to a dirac spike on the realistic solution. (or - if there are many solutions - then many dirac spikes scaled down by the number of them)
if there is a single solution then we could integrate x times the function over all space, to get the x coordinate of the solution (ditto for y and z).
- I have NO idea if this technique is even capable of giving analytical solutions... perhaps..., but even if it does give analytic solutions then i would have to presume the kind of math behind it would make it a TOTALLY impractical mongrel.
Edited by Mark, 16 August 2010 - 11:17 AM.