tl;dr;
In general (when you have issue like this) steps are:
- First you model mathematics/logic of your problem , define set domain, variable types and their relationship or limits.
- Then you analyze your math in form of change (derivatives/integrals) and try to find independent actors ( by following operation order PEMDAS.
- Then you separate each independent actor into smaller tasks that you can test, execute and verify MRE.
- Then you join it all together into cohesive algorithm that implements your solution.
I think you require additional info, to solve an set of equations containing 2 unknowns (ie amount of gold and price) you tend to need either one formula that connect the two or two independent formulas for each.
Since you have 2 variables (unknowns), you can approach this in 4 ways that might branch out later on:
- Forget about one of those variables (GOLD, or PRICE) and just find algorithm that handles one of them - prioritize your data.
- Find new variable that ties them together in some sort of function or formula which limits your applicability - and test it by finding differential/derivative or integral of relationship described by new variable.
- Use them both but independently and then revalue results with some sort of weighted AI trough iteration in order to find some sort of rule or law.
- Find a larger problem (which those 2 variables are part of) and find algorithm for that. - superset for GOLD and PRICE
The way I see it, it seems that you have a floating number limit issue here, since there are infinite amount of Rational Numbers within 0 and 1 in any progressive set ( where amount of GOLD or PRICE increases over time) you will always have some issues matching the GOAL in any random progressive set. So you can approach it by limiting it to specific interval that you may search in and finding direction of "movement" with logic of:
For set A (a in A: a > 0, a in Q+)
and set B (b in B: b > 0, b in Q+)
we have a variable c (c in C, a_i <= c <= b_i | b_i <= c <= a_i, c in Q+)
, direction of mapping (either A or B) is defined by m(a,b,c)=(2C/(a+b))-1
where if m is lesser than 0 it is closer to smaller of a,b. However issue in logic is the domain of the set, since Q is defined by p/q of 2 integers for every real number (float, double) you have issues with range (or step) of linear mapping function.
For any value C (in this case QUANTITY of gold) and sets of A and B (GOAL and FUNDS) you can have potentially infinite amount of values c that are small enough to be disregarded if minimizing the cost is secondary goal. So without any "reference" in amount of gold compared to GOAL (that is derivative of time) you might have issues of never reaching a goal by a wide margin - programmatically.
So you need additional information (or function analysis) in order to find a bordering limit at which buying gold for X price is justified. I would approach this problem from Rational number perspective and represent each price as integer division of closest value, then if DIFFERENCE between GOAL and FUNDS have same GCD as price then I would "buy" it (if GCD isn't 1 and is naturally decreasing as FUNDS are closer to GOAL). Of course in this approach primary numbers are a pain in the butt, and you might still have wide margin to reach your goal but it should be less than removing chunks out of funds.
Second possible approach is from economic standpoint where you need additional variable of "Required Price" or some sort of estimation of wealth of whomever is buying. But that can change your desire for this algo quite a bit, since you will not have diversity in your portfolio and would (sort of) limit your domain to specific range. If in same case as before:
For set A (a in A: a > 0, a in Q+)
and set B (b in B: b > 0, b in Q+)
we have a variable c (c in C, a_i <= c <= b_i | b_i <= c <= a_i, c in Q+)
then price becomes c/a, c/b and which if c is p/q, a is w/e and b is v/u then we have typical Rational division (which is multiplication of its inverse):
c/a = (p/q)/(w/e)=(pe/wq) | c/b = (p/q)/(v/u) = (pu/qv) -> c/a=c*a^-1, c/b=c*b^-1
Then for some Required Price (RP) and some acceptable "leeway"[lw] we can write it as -lw <= some (a^-1, b^-1) <= lw
if RP is also p/q. So if you have Minimum amount of Gold and Capital, RQ = Minimum amount of Gold / Capital ( or Ratio in your second image). This approach will ignore any price that is outside of "leeway" and will tend to have margin as wide as inverse of lw.
This is why you need another variable in data set that has 2 elements (GOLD,PRICE) if you are searching for solution for only one variable (GOLD). You can ignore PRICE and focus on GOLD to GOLD mapping, or you can add some additional variables (such as PRICE, FUNDS, CAPITAL...) that are either combination of two or describe their relationship.
Each step of algorithm is reduction in information, since we can't handle infinity outside of abstractions. You can think about it, and you can model it but once you try to apply it probability rises alot. So here you can either sit down and go trough each and every probability in mapping and try and find some relationship (or theory) or you can simplify it by introducing another variable or relationship.
Hope this helps.