[Restructuring to the mode-chain of responsibility pattern] Restructuring the Harry Potter book purchase offer to the responsibility chain mode

Source: Internet
Author: User

The publishing house wants to promote a set of Harry Potter books. This set of books has a total of five sets, each of which is priced at 8 yuan. If you buy one copy of any two sets, you can get off. If you buy one copy of any three sets, you can get off. If you buy one copy of any four sets, you can get off; if you buy one for each of the five sets, you will be entitled to a discount. In addition to the above discounts, the purchase of a single book is still priced at 8 yuan. For example, if you buy one of the five sets, add one of the first sets, and off for the five books, the first set is priced at 8 yuan. If someone buys 2 books in the first episode, 2 books in the second episode, 2 books in the third episode, 1 book in the fourth episode, and 1 book in the fifth episode. What is the lowest discount price after a discount? Note: Not 51.6 yuan, but 51.2 yuan.

It seems that the discount strategy is used, but here you need to calculate the lowest discount among the several combinations. You can use the responsibility chain model.

Source: http://codingdojo.org/cgi-bin/wiki.pl? Katapotter

Source code: Https://github.com/wubin28/KataPotter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.