Skip to content

Instantly share code, notes, and snippets.

@KonyukhovSergey
Last active August 29, 2015 14:00
Show Gist options
  • Save KonyukhovSergey/11247918 to your computer and use it in GitHub Desktop.
Save KonyukhovSergey/11247918 to your computer and use it in GitHub Desktop.
public bool purchasePack(string name, int count, int oneItemMaxPrice) {
List<AuctionItem> items = new List<AuctionItem>();
foreach(var item in getAuctionBuyList(new AuctionRequestParams(name))) {
double oneItemPrice = (double)item.buyBackPrice / (double)item.item.count;
if(item.buyBackPrice > 0 && oneItemPrice < oneItemMaxPrice) {
items.Add(item);
}
}
items.Sort((a, b) => {
return ((double)a.buyBackPrice / a.item.count) < ((double)b.buyBackPrice / b.item.count) ? -1 : 1;
});
AuctionItem bestPackItem = null;
int minDeltaCount = int.MaxValue;
foreach(var item in items) {
int deltaCount = Math.Abs(item.item.count - count);
if(deltaCount <= minDeltaCount) {
bestPackItem = item;
minDeltaCount = deltaCount;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment