I am creating a game, and have run into quite a tricky problem which I have been wrestling for days. I have been able to turn into somewhat mathematical terms (bare with me, I'm a programmer not mathematician) -- but I am no closer to a solution.
var constants = [1000, 100, 10]; // arbitrary length, arbitrary positive numbers
var contributions = [?, ?, ?]; // an array of each constants respective contribution
Given an array of
constants, I am trying to generate an array of
contributions which represents each
constants contribution to a pool.
SUM(constants[i] * contributions[i]) === pool
That is to say, each constant multiplied by their contribution ... summed up is known as the
Here are the constraints I have to obey:
FOREACH i in constants.length:
constants.length * (constants[i] * contribution[i]) isLessThanOrEqualTo pool
That is to say, if I get the amount of constants I have .. multiply it by constants contribution ... it will always be less than or equal to the size of the pool.
And the last constraint:
All contributions must be less than or equal to 0.01
In other words, no constant can contribute more than 1% of its value to the pool.
Given these constraints, what I want to do is construct my array of
contributions in such a way to maximize
What I am looking for, is a function which turns an array of
constants into an array of
contributions. If anyone could give me any pointers, place to start, library suggestions .. or even work through how this problem would be solved for the example:
constants = [1000, 100, 10] -- i would be highly appreciative.