public void addPizza(Pizza pizza) => pizzas.Add(pizza);
/// <summary> /// Solution 1 /// </summary> /// <param name="team"></param> public void givesPizzas_LargerTeams() { pizzas = pizzas.OrderByDescending(x => x.toppings.Length).ToList(); int pizzasAssignable = Math.Min(numOfPizzas, MaxPeople); foreach (Team.TeamSize size in teamSizes) { while (canMakeGivenSize((int)size, pizzasAssignable) && shouldMakeGivenSize((int)size, pizzasAssignable)) { teams[(int)size].Add(new Team(size)); pizzasAssignable -= (int)size + 2; } } int minAcceptedDupes = 0; int lastNumber = 0; int lastNumberCount = 0; while (pizzasLeft > 0) { if (pizzasLeft == lastNumber) { if (++lastNumberCount == 4) { return; } } else { lastNumberCount = 0; } lastNumber = pizzasLeft; // Console.WriteLine("Pizzas left: " + pizzasLeft); int minDupes = int.MaxValue; for (int currentSize = SIZE_FOUR; currentSize >= SIZE_TWO; currentSize--) { foreach (Team team in teams[currentSize]) { if (team.pizzas.Count < team.MaxPizzas) { // Find best pizza Pizza firstPizza = pizzas.FirstOrDefault(x => !x.Used); // Make an array of the pizzas to compare Pizza[] pizzasToCheck = new Pizza[team.pizzas.Count + 1]; pizzasToCheck[0] = firstPizza; for (int i = 1; i < pizzasToCheck.Length; i++) { pizzasToCheck[i] = team.pizzas[i - 1]; } // See how many duplicates there are, do we want this pizza? int currentDupes = Pizza.NumDuplicates(pizzasToCheck); if (currentDupes <= minAcceptedDupes) { // Take the pizza team.givePizza(firstPizza); pizzas.Remove(firstPizza); // Remove for effeciency } // Save the min for later if (currentDupes < minDupes) { minDupes = currentDupes; } } // If we done, bail. if (pizzasLeft == 0) { return; } } } minAcceptedDupes = minDupes; } }