12
1
Write the shortest program that generates a histogram (a graphical representation of the distribution of data).
Rules:
- Must generate a histogram based on the character length of the words (punctuation included) input into the program. (If a word is 4 letters long, the bar representing the number 4 increases by 1)
- Must display bar labels that correlate with the character length the bars represent.
- All characters must be accepted.
- If the bars must be scaled, there needs to be some way that is shown in the histogram.
Examples:
$ ./histogram This is a hole in one!
1 |#
2 |##
3 |
4 |###
$./histogram Extensive word length should not be very problematic.
1 |
2 |#
3 |#
4 |##
5 |
6 |##
7 |
8 |
9 |#
10|
11|
12|#
./histogram Very long strings of words should be just as easy to generate a histogram just as short strings of words are easy to generate a histogram for.
1 |##
2 |#######
3 |#
4 |#######
5 |###
6 |#
7 |##
8 |##
9 |##
4Please write a specification rather than giving a single example which, solely by virtue of being a single example, cannot express the range of acceptable output styles, and which doesn't guarantee to cover all corner cases. It's good to have a few test cases, but it's even more important to have a good spec. – Peter Taylor – 2013-12-11T00:37:13.890
@PeterTaylor More examples given. – syb0rg – 2013-12-11T02:19:04.710
1>
@PeterTaylor I didn't tag it ascii-art, because it really isn't "art". Phannabus's solution is just fine. – syb0rg – 2013-12-11T13:19:50.843
@PeterTaylor I've added in some rules based on what you described. So far, all the solutions here adhere to all of the rules still. – syb0rg – 2013-12-11T13:45:33.020