# Horizontal graph of word length

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 Sep 7 '15 at 14:15
• @BetaDecay Yes, allowed ........... – Caridorc Sep 7 '15 at 15:10
• Will the input ever have leading or trailing spaces? – PhiNotPi Sep 7 '15 at 15:20
• What 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 Sep 7 '15 at 20:50
• Ok, I realize you're right. Horizontal it is. – nitro2k01 Sep 7 '15 at 21:08

# Ruby, 29 bytes

puts gets.gsub(/\S/,?*).split


# Bash - 60 26 bytes

new solution (thanks manatwork):

for w;{ echo "${w//?/*}";}  old solution: for w;do for((i=1;i<=${#w};i++));do printf \*;done;echo;done


~ $./l This is an example histogram of word length **** ** ** ******* ********* ** **** ******  The only part that might deserve an explanation is ${#w}: it returns the length of the string w.

• Processing separate parameters instead of a single input to avoid completing half of the task, is kind of cheating. Anyway, what you wrote there, can be accomplished in 26 characters: for w;{ echo "${w//?/*}";} – manatwork Sep 9 '15 at 15:12 • Yeah, I realized this was basically a character substitution just after posting that, so I posted another one in sed: codegolf.stackexchange.com/a/57435/7176 – 1ace Sep 9 '15 at 15:15 # sed - 20 bytes s/[^ ]/*/g;s/ +/\n/g  ~$ sed -re 's/[^ ]/*/g;s/ +/\n/g' <<< 'This is an example histogram of word   length'
****
**
**
*******
*********
**
****
******

• @jimmy23013: I edited my answer accordingly, and fixed the multiple space issue :) – 1ace Sep 10 '15 at 9:12