201 / 5.000
I’m currently having problems optimizing my algorithm. It’s about a shop that offers several different goods that are divided into 5 different categories (food, drinks, etc.). If you buy two goods from two different categories, you will receive a 5% discount on these two goods. If you purchase from 3 different categories you will receive a 10% discount. If you purchase from 4 different categories you will receive a 20% discount. If you purchase from 5 different categories you will receive a 25% discount.
The algorthm should optimize the price of any Shoping. Here’s an example in which, for simplicity, I assume that each item costs $5. The customer buys 2 goods from category 1, 2 goods from category 2, 2 goods from category 3, 1 item from category 4 and 1 item of category 5.
If you group [1,2,3,4,5] and [1,2,3] you get one time 25% and one time 10% discount, total price $32,25. But if you group [1,2,3,4] and [1,2,3,5] you get two times 20% total price $32.
MuggyChan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.