Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Greedy Algorithm Imagine that you walk into a restaurant, and want to maximize your caloric intake while staying under your budget of 20
Write a Greedy Algorithm
Imagine that you walk into a restaurant, and want to maximize your caloric intake while staying under your budget of 20 dollars. You step to the counter and see your options of (with each item listed as Name, Price, Calories) . Water, $1.00, 0 Soda, $2.00, 100 Salad, $3.50, 200 . Fries, $4.00, 400 Burger, $6.50, 700 Chicken, $7.00, 500 Ice Cream, $3.00, 400 Please write and implement a greedy algorithm that maximizes your calories while staying under budget. You can do this in the notebook or in a separate file You should test three methods of choosing the "best" item: .The lowest price The highest calories The best calorie/price ratio Your code should include: -A definition of a class (Food) that stores the data for each item, and returns the proper value needed for each "best" method A function that takes in a list of names, prices and calories and returns a menu (a list of Foods) An algorithm that sorts your list, using the three condition described above, from best to worst. It should return a new sorted list, not changing the original Code that keeps a running sum of the calories and cost of your meal. This code will stop building a meal if the cost is over budget. Your code should be flexible enough to change the budget (input it as a parameter) Imagine that you walk into a restaurant, and want to maximize your caloric intake while staying under your budget of 20 dollars. You step to the counter and see your options of (with each item listed as Name, Price, Calories) . Water, $1.00, 0 Soda, $2.00, 100 Salad, $3.50, 200 . Fries, $4.00, 400 Burger, $6.50, 700 Chicken, $7.00, 500 Ice Cream, $3.00, 400 Please write and implement a greedy algorithm that maximizes your calories while staying under budget. You can do this in the notebook or in a separate file You should test three methods of choosing the "best" item: .The lowest price The highest calories The best calorie/price ratio Your code should include: -A definition of a class (Food) that stores the data for each item, and returns the proper value needed for each "best" method A function that takes in a list of names, prices and calories and returns a menu (a list of Foods) An algorithm that sorts your list, using the three condition described above, from best to worst. It should return a new sorted list, not changing the original Code that keeps a running sum of the calories and cost of your meal. This code will stop building a meal if the cost is over budget. Your code should be flexible enough to change the budget (input it as a parameter)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started