/// <summary> /// If you're willing to spend 'resourcesAvailable' and want to buy something with /// additively increasing cost each purchase (start at priceStart, add by priceAdd, /// already own currentOwned), how much of it can you buy? /// </summary> public static BigDouble AffordArithmeticSeries(BigDouble resourcesAvailable, BigDouble priceStart, BigDouble priceAdd, BigDouble currentOwned) { var actualStart = priceStart + currentOwned * priceAdd; //n = (-(a-d/2) + sqrt((a-d/2)^2+2dS))/d //where a is actualStart, d is priceAdd and S is resourcesAvailable //then floor it and you're done! var b = actualStart - priceAdd / 2; var b2 = BigDouble.Pow(b, 2); return(BigDouble.Floor( (BigDouble.Sqrt(b2 + priceAdd * resourcesAvailable * 2) - b) / priceAdd )); }
public static BigDouble Sqrt(this BigDouble value) { return(BigDouble.Sqrt(value)); }