28
1
Input
A list of words separated by any number of spaces.
Output
A horizontal ASCII art graph, where the n-th line is composed by as many asterisks (*
) as the n-th word is long.
Example usage
The >
signals user input, you should not input it when testing the program.
> This is an example histogram of word length
****
**
**
*******
*********
**
****
******
> a aa aaa aaaa aaaaa
*
**
***
****
*****
> double space example
******
*****
*******
Reference implementation
In case of doubt over the specification, the output of your program should match exactly that of the below program under all inputs.
puts gets.chomp.split.map{|word| '*' * word.length}.join("\n")
So is a trailing newline allowed? crosses fingers – Beta Decay – 2015-09-07T14:15:10.720
@BetaDecay Yes, allowed ........... – Caridorc – 2015-09-07T15:10:28.633
Will the input ever have leading or trailing spaces? – PhiNotPi – 2015-09-07T15:20:22.787
Well the Ruby answer is right there in the question, so there isn't much room for improvement. If you're using
puts
you don't need thejoin
though, as it would be done anyway when the array is passed to stdout. :-D – Level River St – 2015-09-07T17:06:33.293@PhiNotPi No, fully disallowed – Caridorc – 2015-09-07T18:30:29.753
8What you're describing is not a histogram. A histogram would show the number of words with x characters on line x. In the first example, line 1 would have 0 asterisks (no words with length 1) line 2 would have 3 asterisks (is, an, of) and so on. – nitro2k01 – 2015-09-07T20:50:18.353
@nitro2k01
histogram
is indeed not accurate, how would you rename this challange? – Caridorc – 2015-09-07T20:55:38.357Just horizontal graph I guess. Or more like vertical graph, where vertical refers to the Y axis the word index is on. – nitro2k01 – 2015-09-07T21:00:28.803
@nitro2k01 horizontal graph seems more clear – Caridorc – 2015-09-07T21:02:34.630
1Ok, I realize you're right. Horizontal it is. – nitro2k01 – 2015-09-07T21:08:24.363
Does the input need to come from stdin or can it be from command line arguments? – slebetman – 2015-09-08T07:33:44.403
@slebetman stdin only – Caridorc – 2015-09-08T09:03:31.033