I’d like to ask:
- I’ve got any positive integer number, let’s say:
10 - Then I got random integer numbers (random count of them too), let’s say:
5, 7, 8 - I want to calculate floating-point number such as:
5*x + 7*x + 8*x = 10 - I got that a this moment, but I want to have it common lower boundary limit (let’s say
3), such as:
5 * x > 3
7 * x > 3
8 * x > 3
- It is possible to correct the numbers (ratios) in order to achieve this state, so in this particular example it will be like this:
sum = 5 + 7 + 8 = 20 x = 10 (total) / 20 (sum) x = 0.5 results: 5*0.5 + 7*0.5 + 8*0.5 = 2.5 + 3.5 + 4 = 10 (total)
So far so good, but 2.5 is now lower then a given min. limit 3, so how to solve this!
Is it possible, if so, how? (in C# preferably)
Let us take your example and see how WE would solve it.
i shall change the use of 5x 7x 8x to the use of 5x 7y 8z because its already been decided that these MUST change to fit the requirements and therefore will not all be the same.
however, 5 times 0.5 is NOT greater than 3
therefore to make 5 times x atleast 3 we must increase the total by 0.5
as 3(the number you atleast want) – 2.5(the number you have) is 0.5
so the TOTAL must increase by 0.5.
as 5 times x must = 3 we can see that x must = 3 divided by 5 which gives us 0.6
all together = 10.5…ah, balls.
ok so we can see that y or z must be made smaller to make sure that the answer is still exactly 10
so lets pick 8 times z = 4 (as 4 is the furthers from 3 and will give us the most lee way)
0.5 divided by 8 = 0.0625
so z must decrease by 0.0625 to counteract the 0.5 increase from 5 times x
so z now = 0.5 – 0.0625 which is 0.4375
3 plus 3.5 plus 3.5 = 10! we nailed it! yaaay
i hope this helped! if not well i enjoyed doing it anyway 😀
To summarise, we had to increase x so that 5x was atleast 3, but the increase in x meant the answer was greater than 10, therefore either y or z had to decrease by whatver the total increasewas to counteract this, we do that increase divided by one of the other numbers, to figure out how much we need to subtract from z or y to make it = the perfect 10 again