View Single Post
  #1  
Old July 29th, 2009, 03:47 AM
milkies milkies is offline
Newbie
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
milkies is on a distinguished road
Default Help find the algorithm

Hi all,

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
Reply With Quote