I have two numbers X and Y. The total of these two numbers cannot go over 500. I need a generic way of calculating that when (X * 3) + Y is greater than 500, I move part of X into Y so (X*3) + Y is <= 500 (preferably as close to 500 as possible).
For example, if X is 180 and Y is 0.
Moving 20 from X to Y gives
X = 160
Y = 20
(160*3) = 480 + Y(20) = 500
Can anybody help me work out an algorithm to calculate this?
Thanks for any help