I have a List with about 500 items in and I want every possible combination of 10 "digits" that means I would need way too many loops 500^10
Is there a faster/better way?
Idk if code helps here since my current consists of 10 foreach and the first 10000 uniques took me 30min.
I know my code isn't very optimised but if 1 iteration takes 250ms or 25ms both in a 500^10 take way too long Thanks in advance!
foreach (var item1 in itemList)
{
foreach (var item2 in itemList)
{
foreach (var item3 in itemList)
{
foreach (var item4 in itemList)
{
foreach (var item5 in itemList)
{
foreach (var item6 in itemList)
{
foreach (var item7 in itemList)
{
foreach (var item8 in itemList)
{
foreach (var item9 in itemList)
{
foreach (var item10 in itemList)
{
TradeUp t = new TradeUp();
t.tradeUpItems.AddRange(new List<Price>() { item1, item2, item3, item4, item5, item6, item7, item8, item9, item10 });
t.Input = t.tradeUpItems.Sum(x => Double.Parse(x.price.Replace(".", ",")));
double totalOutcomeItems = 0;
double avgFloat = 0;
List<Price> nextLvlItems = new List<Price>();
foreach (var item in t.tradeUpItems)
{
avgFloat += item.ConditionRanges[item.Condition].Upper - item.ConditionRanges[item.Condition].Lower;
var oneItemsNextItems = allItems.Where(x => qualityList[i + 2].Contains(x) && x.Collection == item.Collection);
nextLvlItems.AddRange(oneItemsNextItems.DistinctBy(x => x.WeaponName).ToList());
}
t.Outcomes.UnionWith(nextLvlItems);
totalOutcomeItems = 1.0 / nextLvlItems.Count();
avgFloat = avgFloat / t.tradeUpItems.Count();
var duplicateList = t.Outcomes.Select(x => new { Element = x, Count = nextLvlItems.Count(y => y.WeaponName == x.WeaponName) });
//t.Outcomes.ToList().ForEach(x => t.Outcome += duplicateList.FirstOrDefault(y => y.Element.WeaponName == x.WeaponName && x.market_hash_name.Contains(x.ConditionRanges.FirstOrDefault(z => z.Value.Lower < (double)((x.MaxFloat - x.MinFloat) * avgFloat + x.MinFloat) && z.Value.Upper > (double)((x.MaxFloat - x.MinFloat) * avgFloat + x.MinFloat)).Key)).Count * Double.Parse(x.price.Replace(".",",")) * count);
foreach (var x in t.Outcomes.ToList())
{
var test1 = duplicateList.FirstOrDefault(y => y.Element.WeaponName == x.WeaponName);
var test = t;
var test2 = qualityList[i + 2].FirstOrDefault(y => y.WeaponName == x.WeaponName && y.market_hash_name.Contains(GetCondition(y)));
var value = Double.Parse(test2.price.Replace(".", ","));
string GetCondition(Price p)
{
var maxmin = x.MaxFloat - x.MinFloat;
var floatVal = (double)(maxmin * avgFloat + x.MinFloat);
var itemxy = p.ConditionRanges.FirstOrDefault(z => z.Value.Lower <= floatVal && z.Value.Upper >= floatVal).Key;
return itemxy;
}
t.Outcome += test1.Count * value * totalOutcomeItems;
}
finishedTradeUps.Add(t);
}
}
}
}
}
}
}
}
}
}
return finishedTradeUps.ToList().OrderByDescending(x => x.Profit).ToList();