← Back to puzzles

012 The Perfect Menu

You are a chef running a small restaurant; due to the small size of your kitchen, you always have a set menu with one appetizer, one main dish, and one dessert. After service is over, you immediately check the Yelp reviews for the day. You suspect that guests like some dishes more than others, but they don't leave very detailed reviews, just an average rating for the entire meal. In spite of this, maybe you can still figure out which dishes they prefer?

Assuming that each dish has a hidden taste rating (an integer between 1 and 5), and that each Yelp rating equals the average of the three dishes served, write a program that calculates the taste rating of each dish. Given a list of menus and their Yelp ratings of the form:

APPETIZER,MAIN COURSE,DESSERT,YELP RATING

...your program should output each dish's taste rating, sorted alphabetically by dish name, like this:

DISH 1: RATING
DISH 2: RATING
...

You can assume that each dish has only one possible rating.

For example, given the following input:

Gazpaco,Ragu,Tiramisu,3
Gazpaco,Trippa alla Romana,Panettone,1
Gazpaco,Ragu,Panettone,2
Caprese,Trippa alla Romana,Panettone,2

The output should be:

Caprese: 4
Gazpaco: 1
Panettone: 1
Ragu: 4
Tiramisu: 4
Trippa alla Romana: 1

Buon appetito!