Problem 003

Problem

Description

Charlie Weis and Jimmy Clausen

After a long and grueling summer practice, Coach Weis is ready to get nasty and return Notre Dame to glory [1]. Before doing this however, he needs to first address some of the criticisms of his play calling. To do this, Charlie has compiled a list of the types of plays (pass, run), the direction of the play calls (left, middle, right), and the amount of yards gained for each play into a single spreadsheet. Unfortunately, OIT mysteriously revoked the Excel license from his computer, and so he needs you to generate ASCII histograms of the play calls. Once he can examine the play calling visually, he can make the adjustments necessary to finally beat USC and BC [2].

Input

The data is in standard CSV format, with the following fields:

  1. Play Type: Run, Pass
  2. Direction: Left, Middle, Right
  3. Yardage: Amount of yards the play generated

Example Input:

Run, Left, 3.0
Run, Right, 2.0
Run, Middle, -15.0
Pass, Left, 4.0
Run, Middle, 2.0
Pass, Left, 14.0
Run, Left, 8.0
Run, Right, 1.0

Output

You will need to output a histogram for each of the fields. The format of the histograms should be in the format shown below in the example output:

Play Type:
    Run     |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx               |
    Pass    |xxxxxxxxxxxxxxx                                             |

Direction:
    Left    |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx                              |
    Middle  |xxxxxxxxxxxxxxx                                             |
    Right   |xxxxxxxxxxxxxxx                                             |

Yardage:
    00 - 09 |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx       |
    10 - 19 |xxxxxxxx                                                    |
    20 - 29 |                                                            |
    30 - 39 |                                                            |
    40 - 49 |                                                            |
    50 - 59 |                                                            |
    60 - 69 |                                                            |
    70 - 79 |                                                            |
    80 - 89 |                                                            |
    90 - 99 |                                                            |

The x histogram bars represent the percentage for that field and shall be 60 characters wide (not including the | posts). If an exact number of characters is not possible, then rounding is to be used. For Yardage, split the plays into 10 yard increments, beginning with 00 to 09. Negative plays are to be considered 0 yards. Remember to use the exact same formating (i.e. line up the columns, etc.).

[1]This is not a repeat from 2002, 2003, 2004, 2005, 2006, 2007, 2008.
[2]This has yet to happen since I've been here. I blame Ryan.

Solution

Approach

Read the input and parse the CSV formatted lines. Tabulated the different fields and then print out the results.

Input/Output

Source Code