private bool IsCostInRange(decimal cost) => cost <= Cash && cost > BottomCashLimit; // Take only the best combinations. private decimal GetCombinationCostById(ulong id) { // Convert an ID into the combination as if all combinations were listed in order. // This algorithm basically converts base ten to base whatever the max stock quantities are. decimal cost = 0; for (int i = 0; i < MaxStockQuantities.Length; i++) { StockQuantity maxStockQuantity = MaxStockQuantities[i]; cost += maxStockQuantity.Stock.Price * (uint)(id % (maxStockQuantity.Quantity + 1)); id /= maxStockQuantity.Quantity + 1; } return(cost); }
private StockQuantity[] GetCombinationById(ulong id) { // Convert an ID into the combination as if all combinations were listed in order. // This algorithm basically converts base ten to base whatever the max stock quantities are. StockQuantity[] stockQuantities = new StockQuantity[MaxStockQuantities.Length]; for (int i = 0; i < MaxStockQuantities.Length; i++) { StockQuantity maxStockQuantity = MaxStockQuantities[i]; stockQuantities[i] = new StockQuantity { Stock = maxStockQuantity.Stock, Quantity = (uint)(id % (maxStockQuantity.Quantity + 1)) }; id /= maxStockQuantity.Quantity + 1; } return(stockQuantities); }