SmartK8
SmartK8

Reputation: 2626

How to divide total by given factors and with lower boundary?

I'd like to ask:

5 * x > 3
7 * x > 3
8 * x > 3

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)

Upvotes: 0

Views: 304

Answers (3)

RhysW
RhysW

Reputation: 453

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.

So currently you get a total answer of 10 by having 

5 times 0.5 = 2.5
7 times 0.5 = 3.5
8 times 0.5 = 4

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

now lets recalculate your sum

5 times 0.6 = 3
7 tiems 0.5 = 3.5
8 times 0.5 = 4

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

lets redo your sum with these new numbers!

5 times 0.6 = 3
7 times 0.5 = 3.5
8 times  0.4375 = 3.5

3 plus 3.5 plus 3.5 = 10! we nailed it! yaaay

i hope this helped! if not well i enjoyed doing it anyway :D

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

Upvotes: 1

Johnny_D
Johnny_D

Reputation: 4652

seems you have to solve a task first, only then code it. Let's see your given conditions All your numbers mupltipled to X must be larger then 3, that's why max count of them should be 6, because 7 * 3 is already 21, which is larger then 20. Second, depending on count of your number, we have to calculate minimal value of numbers. If it is 6, we have minimal value rest of division 20 to 6 = 3, if it is 5 then we have 20 % 5 = 4. Only on this two conditions we can calculate "X".

Upvotes: 0

Sasha
Sasha

Reputation: 8860

YOur requirements are contradicting. It is impossible to guarantee that 5*x + 7*x + 8*x = 10 in the same time with 5*x > 3 if x is single value. If you can use 5*x + 7*y + 8*z = 10, then it becomes possible, if you have 3*value_count < 10 but is this other task I suppose

Upvotes: 0

Related Questions