'Calculating every permutation given a condition and total amount
I need to calculate every permutation that a user can select from a menu. The user can only select 1 main, 2 sides and 1 drink. The dictionaries below show the menu items available to the user. Certain menu items are priced higher depending on the ingredients. The name of the menu item is placed as the dictionary key and the value is how much the menu item is worth.
main = {"double_burger": 8, "double_cheese_burger": 8, "sandwhich":6, "wrap":6, "burger":6, "cheese_burger":6, "mini_burger":4, "small_wrap":4}
sides = {"coleslaw": 2, "mash":2, "chips":2, "biscuit":2, "large_chips":4, "chicken_wings":4, "salad":4}
drinks = {"coke":4, "pepsi":2, "juice":4, "oreo_milkshake":6, "strawberry_milkshake":6, "water":2}
To make it easier for the user, they have to select what size meal they would want which indicates what they can order. Below is a dictionary showing the meal sizes.
totals = {"regular":12, "large":16, "max":20}
If a user selects regular, their order can only be to the size of 12 in total. So for example, they might select a mini_burger as a main which is 4, coleslaw and chips as a side which is 2,2 and coke as a drink which is 4. Therefore a user has created an order for 12 points.
There are a few conditions on what main a user can order depending on the size of their meal.
- Regular -
mini_burger,small_wrap - Large -
sandwhich,wrap,burger,cheese_burger,mini_burger - Max -
double_burger,double_cheese_burger
I have tried looking into from itertools import permutations however I am not sure how I can add the above conditions. I am looking for a list of all combinations that a user can order.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
