static void Main(string[] args) { int elementsCount = 2; int setCount = 3; CombinationsGenerator.Generate(setCount, new int[elementsCount]); }
static void Main() { string[] elements = { "test", "rock", "fun" }; var combinations = CombinationsGenerator.GenerateCombinations(elements, 2); PrintVars(combinations); }
public static void Main() { int elementsCount = 2; int setCount = 4; CombinationsGenerator.Generate(setCount, new int[elementsCount]); }
public void BasicTest2() { var o1 = 1; var o2 = 2; var o3 = 3; var list = new List <object> { o1, o2, o3 }; var combinationsGenerator = new CombinationsGenerator(); const int numberOfBaskets = 3; var basketCombinations = combinationsGenerator.GetCombinationsInBaskets(list, numberOfBaskets); var expectedBasketCombinations = new List <BasketCombination <object> > { // null - разделитель между корзинами BasketCombinationWith <object>(o1, o2, o3, null, null), BasketCombinationWith <object>(null, o1, o2, o3, null), BasketCombinationWith <object>(null, null, o1, o2, o3), BasketCombinationWith <object>(o1, null, o2, null, o3), // первый в первой, второй во второй, третий в третьей BasketCombinationWith <object>(o1, null, o3, null, o2), BasketCombinationWith <object>(o2, null, o1, null, o3), BasketCombinationWith <object>(o2, null, o3, null, o1), BasketCombinationWith <object>(o3, null, o1, null, o2), BasketCombinationWith <object>(o3, null, o2, null, o1), BasketCombinationWith <object>(o1, null, o2, o3, null), BasketCombinationWith <object>(o1, null, null, o2, o3), BasketCombinationWith <object>(o1, null, o2, null, o3), BasketCombinationWith <object>(o1, null, o3, null, o2), BasketCombinationWith <object>(o2, null, o1, o3, null), BasketCombinationWith <object>(o2, null, null, o1, o3), BasketCombinationWith <object>(o2, null, o1, null, o3), BasketCombinationWith <object>(o2, null, o3, null, o1), BasketCombinationWith <object>(o3, null, o2, o1, null), BasketCombinationWith <object>(o3, null, null, o2, o1), BasketCombinationWith <object>(o3, null, o2, null, o1), BasketCombinationWith <object>(o3, null, o1, null, o2), BasketCombinationWith <object>(o1, o2, null, o3, null), BasketCombinationWith <object>(o1, o2, null, null, o3), BasketCombinationWith <object>(o1, o3, null, o2, null), BasketCombinationWith <object>(o1, o3, null, null, o2), BasketCombinationWith <object>(o2, o3, null, o1, null), BasketCombinationWith <object>(o2, o3, null, null, o1), }; foreach (var expected in expectedBasketCombinations) { var matchingResult = basketCombinations.SingleOrDefault(x => BasketsAreEqual(expected, x)); Assert.NotNull(matchingResult, "Ожидаемый вариант {0} не найден", GetVariantText(expected)); } Assert.That(basketCombinations.Count, Is.EqualTo(expectedBasketCombinations.Count)); }
public void EqualObjectsInCollectionTest() { var object1 = new object(); var list = new List <object> { object1, object1 }; var combinationsGenerator = new CombinationsGenerator(); var combinations = combinationsGenerator.GetCombinations(list); Assert.That(combinations.Count, Is.EqualTo(3)); var expectedCombination1 = new List <object>(); var expectedCombination2 = new List <object> { object1 }; var expectedCombination3 = new List <object> { object1, object1 }; var expectedCombinationsList = new List <List <object> > { expectedCombination1, expectedCombination2, expectedCombination3, }; foreach (var expected in expectedCombinationsList) { Assert.That(combinations.Any(x => x.Elements.AreElementsAreEqualTo(expected)), "Не найдена комбинация " + GetListString(expected)); } }
public void EqualObjectsInCollectionTests() { var list = new List <int> { 1, 1 }; var combinationsGenerator = new CombinationsGenerator(); const int numberOfBaskets = 2; var basketCombinations = combinationsGenerator.GetCombinationsInBaskets(list, numberOfBaskets); var expectedBasketCombinations = new List <BasketCombination <int> > { // null - разделитель между корзинами BasketCombinationWith <int>(1, 1, null), BasketCombinationWith <int>(1, null, 1), BasketCombinationWith <int>(null, 1, 1), }; foreach (var expected in expectedBasketCombinations) { var matchingResult = basketCombinations.SingleOrDefault(x => BasketsAreEqual(expected, x)); Assert.NotNull(matchingResult, "Ожидаемый вариант {0} не найден", GetVariantText(expected)); } Assert.That(basketCombinations.Count, Is.EqualTo(expectedBasketCombinations.Count)); }
public void EmptyListTest() { var list = new List <int> { }; var combinationsGenerator = new CombinationsGenerator(); var combinations = combinationsGenerator.GetCombinations(list); Assert.That(combinations.Count, Is.EqualTo(1)); Assert.That(combinations.Single().Elements.Count == 0); }
public void NegativeNumberOfBasketsTest() { var combinationsGenerator = new CombinationsGenerator(); var list = new List <int> { 1, 2, 3 }; const int numberOfBaskets = -10; Assert.Throws <Check.CheckException>(() => combinationsGenerator.GetCombinationsInBaskets(list, numberOfBaskets), "Минимальное число корзин - ноль."); }
public void BasicTest2() { var object1 = 1; var object2 = 2; var object3 = 3; var list = new List <object> { object1, object2, object3 }; var combinationsGenerator = new CombinationsGenerator(); var combinations = combinationsGenerator.GetCombinations(list); Assert.That(combinations.Count, Is.EqualTo(8)); var expectedCombination1 = new List <object>(); var expectedCombination2 = new List <object> { object1 }; var expectedCombination3 = new List <object> { object1, object2 }; var expectedCombination4 = new List <object> { object1, object3 }; var expectedCombination5 = new List <object> { object1, object2, object3 }; var expectedCombination6 = new List <object> { object2 }; var expectedCombination7 = new List <object> { object2, object3 }; var expectedCombination8 = new List <object> { object3 }; var expectedCombinationsList = new List <List <object> > { expectedCombination1, expectedCombination2, expectedCombination3, expectedCombination4, expectedCombination5, expectedCombination6, expectedCombination7, expectedCombination8, }; foreach (var expected in expectedCombinationsList) { Assert.That(combinations.Any(x => x.Elements.AreElementsAreEqualTo(expected)), "Не найдена комбинация " + GetListString(expected)); } }
static void Main() { Console.WriteLine("For n=4 k=2"); Console.WriteLine("Combinations with duplicates:"); var combs = CombinationsGenerator.GenerateCombinations(4, 2, false); PrintCombs(combs); Console.WriteLine("Combinations without duplicates:"); combs = CombinationsGenerator.GenerateCombinations(4, 2, true); PrintCombs(combs); }
public void TimeBasedTest2() { const int numberOfObjects = 12; var list = new List <object>(); numberOfObjects.Times(() => list.Add(new object())); var combinationsGenerator = new CombinationsGenerator(); var combinations = combinationsGenerator.GetCombinations(list); }
public void ZeroNumberOfBasketsTest() { var combinationsGenerator = new CombinationsGenerator(); var list = new List <int> { 1, 2, 3 }; const int numberOfBaskets = 0; var combinations = combinationsGenerator.GetCombinationsInBaskets(list, numberOfBaskets); Assert.That(combinations.Count, Is.EqualTo(0)); }
public static List <Dish> GenerateAllDifferentDishes() { // Getting all data about ingredients var allIngredientsList = GameData.ingredientDict.Values.ToList(); allIngredientsList.RemoveAll(el => el.type == IngredientType.Null); // Generating all combinations without repeating var intCombinations = CombinationsGenerator.GetAllCombinationsWithRepeats(5, allIngredientsList.Count - 1); // Creating list with all generated dishes var unsortedResult = intCombinations.ConvertAll(indArray => new Dish(IngredientListFromIndeces(indArray))); // Returning sorted by points list return(unsortedResult.OrderBy(el => el.points).ToList()); }
public void GetPermutationsTest() { CombinationsGenerator permutations = new CombinationsGenerator(); List <List <int> > combos = permutations.GetAllCombos(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }.ToList()).Where(x => x.Count == 2).ToList(); foreach (var permu in combos) { foreach (var i in permu) { Trace.Write(i.ToString() + " "); } Trace.Write("\n"); } List <NetworkComponent> test = new List <NetworkComponent>() { new NetworkComponent { ID = "1c" }, new NetworkComponent { ID = "2c" }, new NetworkComponent { ID = "3c" }, new NetworkComponent { ID = "4c" }, new NetworkComponent { ID = "5c" }, new NetworkComponent { ID = "6c" }, }; List <List <NetworkComponent> > combosNC = permutations.GetAllCombos(test).Where(x => x.Count == 2).ToList(); foreach (var permu in combosNC) { foreach (var i in permu) { Trace.Write(((NetworkComponent)i).ID.ToString() + " "); } Trace.Write("\n"); } }
public void ValueTypesTest() { var list = new List <object> { 1, 1, 1 }; var combinationsGenerator = new CombinationsGenerator(); var combinations = combinationsGenerator.GetCombinations(list); Assert.That(combinations.Count, Is.EqualTo(4)); var expectedCombination1 = new List <object>(); var expectedCombination2 = new List <object> { 1 }; var expectedCombination3 = new List <object> { 1, 1 }; var expectedCombination4 = new List <object> { 1, 1, 1 }; var expectedCombinationsList = new List <List <object> > { expectedCombination1, expectedCombination2, expectedCombination3, expectedCombination4, }; foreach (var expected in expectedCombinationsList) { Assert.That(combinations.Any(x => x.Elements.AreElementsAreEqualTo(expected)), "Не найдена комбинация " + GetListString(expected)); } }
public static void Main() { CombinationsGenerator.Generate(2, 0, new string[] { "test", "rock", "fun" }); }
static void Main(string[] args) { Console.Title = "Stock Combinations Generator by Yonatan"; string[] symbols = ConsoleHelpers.Prompt("Enter the stock ticker symbols separated by spaces").Trim().Split(' '); decimal cash = Math.Abs(decimal.Parse(ConsoleHelpers.Prompt("Enter the amount of cash you would like to trade ($)"))); ConsoleHelpers.Highlight("Loading current stock prices..."); CombinationsGenerator generator = new CombinationsGenerator(symbols, cash); Console.WriteLine(); ConsoleHelpers.Underline($"Loaded initial stock prices (as of {DateTime.Now})"); Console.WriteLine(string.Join("\n", generator.Stocks)); Console.WriteLine(); ConsoleHelpers.Underline("Max trade quantity of each stock"); Console.WriteLine(string.Join("\n", (object[])generator.MaxStockQuantities)); Console.WriteLine(); ConsoleHelpers.Underline("Number of possible combinations"); Console.WriteLine(generator.NumberOfPossibleCombinations.ToString("N0")); Console.WriteLine(); ConsoleHelpers.Highlight("Generating combinations..."); generator.GenerateCombinations(); Console.WriteLine(); if (generator.HasCombinations) { int baseCursorTop = Console.CursorTop; while (true) { generator.UpdateStockPrices(); ConsoleHelpers.Underline($"Updated stock prices (as of {DateTime.Now})"); Console.WriteLine(string.Join("\n", generator.Stocks)); Console.WriteLine(); ConsoleHelpers.Highlight("Press ENTER to refresh the stock prices."); Console.WriteLine(); ConsoleHelpers.Underline("Trade one of these quantities"); IEnumerable <StockQuantity[]> combinations = generator.GetBestCombinations(100); Console.WriteLine(string.Join("\t", combinations.First().Select(c => c.Stock.Symbol)) + "\tLeft\tCost"); foreach (StockQuantity[] stockQuantityList in combinations) { decimal combinationCost = CombinationsGenerator.GetCombinationCost(stockQuantityList); Console.WriteLine(string.Join("\t", stockQuantityList.Select(c => c.Quantity)) + "\t$" + (cash - combinationCost).ToString("N") + "\t$" + combinationCost.ToString("N")); } Console.SetWindowPosition(0, baseCursorTop); Console.ReadLine(); Console.CursorTop = baseCursorTop; } } else { ConsoleHelpers.WriteInvesre("Not enough cash for a good combination..."); Console.ReadLine(); } }