public IList<Book> ApplyDiscounts(IList<Book> books)
        {
            var discounts = _locator.GetDiscountsFor(books)
            .OrderBy(x => x.Percentage);

              var bestDiscountedBooks = books;

              for(int i = 1; i <= discounts.Count(); i++)
              {
               var testDiscountBooks = books.Clone();

            foreach(var discount in discounts.Take(i).OrderByDescending(x => x.Percentage))
            {
              while(discount.IsSatisfiedBy(testDiscountBooks))
            discount.Apply(testDiscountBooks);
            }

            if(testDiscountBooks.Sum(x => x.Price) < bestDiscountedBooks.Sum(x => x.Price))
              bestDiscountedBooks = testDiscountBooks;
              }

              return bestDiscountedBooks;
        }
Example #2
0
 public Hand(IList<ICard> cards)
 {
     this.Cards = cards.Clone<ICard>();
 }