Exemple #1
0
        private List <BooksCombo> CalculateCombos(List <Int32> books)
        {
            List <BooksCombo> combos = new List <BooksCombo>();

            for (Int32 i = 1; i <= books.Distinct().Count(); i++)
            {
                BooksCombo combo = new BooksCombo();

                foreach (Int32 book in books)
                {
                    IEnumerable <List <Int32> > groups = combo.GetGroupsThatDoNotContainBook(book);

                    List <Int32> group = groups.FirstOrDefault(g => g.Count < i);
                    if (group != null)
                    {
                        group.Add(book);
                    }
                    else
                    {
                        combo.AddBook(book);
                    }
                }

                combos.Add(combo);
            }

            return(combos);
        }
Exemple #2
0
        private Decimal CalculateComboPrice(BooksCombo combo)
        {
            Decimal comboPrice = 0;

            foreach (List <Int32> books in combo.Groups)
            {
                Decimal discountFactor = CalculateDiscountFactor(books);
                comboPrice += books.Count * singlePrice * discountFactor;
            }

            return(comboPrice);
        }