| Bytes | Lang | Time | Link |
|---|---|---|---|
| 007 | Husk | 240912T123544Z | int 21h |
| 009 | 05AB1E | 241001T145704Z | Kevin Cr |
| 018 | Zsh | 241001T064751Z | roblogic |
| 009 | Uiua | 240923T212012Z | janMakos |
| 059 | C gcc | 240923T212806Z | G. Sliep |
| 029 | AWK | 240924T081429Z | Marius_C |
| 031 | AWK | 240918T092812Z | cnamejj |
| 010 | J | 240918T185413Z | Conor O& |
| nan | 240918T063314Z | Aaron | |
| 066 | Red | 240918T075750Z | Galen Iv |
| 005 | Vyxal | 210618T052227Z | emanresu |
| 005 | Vyxal 3 j | 240913T121249Z | pacman25 |
| 006 | Perl 5 + p040l012 | 150907T125848Z | Dom Hast |
| 067 | Rockstar | 240913T101314Z | Shaggy |
| 006 | Japt R | 240912T131655Z | Shaggy |
| nan | 150907T205241Z | adroitwh | |
| 092 | Beam | 150910T223412Z | MickyT |
| 022 | O | 150910T144144Z | kirbyfan |
| 031 | K5 | 150910T144447Z | kirbyfan |
| 050 | PHP 5.3 | 150908T072416Z | jrenk |
| 020 | sed | 150909T151302Z | 1ace |
| 026 | Bash | 150909T150537Z | 1ace |
| 029 | Ruby | 150909T224807Z | daniero |
| 010 | J | 150909T153358Z | Alex Shr |
| nan | 150909T140924Z | Shravan | |
| 538 | Retina | 150907T125413Z | NinjaBea |
| 031 | PowerShell | 150908T142556Z | AdmBorkB |
| 075 | Matlab / Octave | 150908T093459Z | Luis Men |
| 054 | Matlab | 150909T105531Z | Hoki |
| nan | 150908T144649Z | Patrick | |
| 037 | JavaScript ES6 | 150908T062120Z | Cristian |
| 043 | Python 3 | 150907T140739Z | J F |
| nan | 150907T134959Z | Qwertiy | |
| 050 | Julia | 150907T221423Z | Alex A. |
| 037 | ><> | 150907T182702Z | cole |
| 011 | CJam | 150907T195451Z | Reto Kor |
| 033 | R | 150907T195621Z | flodel |
| 031 | Haskell | 150907T171509Z | nimi |
| 106 | C++14 | 150907T184329Z | sweerpot |
| 009 | Gema | 150907T143716Z | manatwor |
| 072 | STATA | 150907T143157Z | bmarks |
| 038 | R | 150907T125810Z | David Ar |
| 102 | Java | 150907T141553Z | Koekje |
| 072 | Python 3 | 150907T133025Z | Beta Dec |
| 040 | SWIProlog | 150907T131749Z | Fatalize |
| 009 | Pyth | 150907T130911Z | isaacg |
| 010 | CJam | 150907T124225Z | Optimize |
Husk, 7 bytes
moR'*Lw
Takes a string as an input and outputs a horizontal ASCII art graph.
Explanation:
w # Split the string into a list of words
m # Map over the list:
R # Repeat
'* # A literal '*'
L # Times the length of the word
o # ?This is not completely clear
The role of o is to construct two functions into a single one - the first function is R with the argument '*, the second is L.
05AB1E, 9 bytes
'*I#õKδ∍»
Try it online or verify all test cases.
Or alternatively:
#õKDS'*:»
Try it online or verify all test cases.
Or alternatively (if the input are only letters and spaces):
áS'*:#õK»
Try it online or verify all test cases.
Explanation:
'* '# Push "*"
I # Push the input-string
# # Split it on spaces
õK # Remove all empty strings ""
δ # Apply double-vectorized:
∍ # Extend the "*" to a length equal to the substring
» # Join by newlines
# (after which the result is output implicitly)
# # Split the (implicit) input-string on spaces
õK # Remove all empty strings ""
D # Duplicate this list of substrings
S # Convert the copy to a flattened list of characters
'*: '# Replace all those characters with "*" in the list of substrings
» # Join by newlines
# (after which the result is output implicitly)
á # Only keep the letters of the (implicit) input-string
S # Convert it to a list of characters
'*: '# Replace all those letters in the (implicit) input-string with "*"
# # Split it on spaces
õK # Remove all empty strings ""
» # Join by newlines
# (after which the result is output implicitly)
Zsh, 18 bytes
for w;<<<${w//?/*}
Alternatively, for 23 bytes: Try it online!
sed 's/[^ ]/*/g'|rs 0 1
Uiua, 13 12 9 bytes
⊜&p⤙+@)±⌵
Explanation
⊜&p⤙+@)±⌵
±⌵ # mask of alphabetic chars
+@) # add ascii ')' (0 -> ')' and 1 -> '*')
⊜ ⤙ # for contiguous sections of the original mask:
&p # print with newline
C (gcc), 49 47 43 59 bytes
p;f(x){read(0,&x,1)&&f(p=x,(x|p)^32&&putchar(x^32?42:10));}
Many bytes added thanks to jdt to fix the requirement to handle consecutive spaces.
AWK, 30 31 bytes
gsub(/[^ ]/,"*")gsub(/ +/,"\n")
Thanks to Marius_Couet for the bug fix!
Another regex program...
gsub("[^ ]","*") - change all "not space" chars to "*"
gsub(/ +/,"\n") - change all spaces to LF's
the input is STDIN by default, and the result is printed to STDOUT by default as well.
J, 10 bytes
'*'"0&>@;:
For context, the other J answer is not a conventional function, but rather a REPL expression expecting its input immediately after. The more conventional representation nowadays, as a verb, would be '*'$~$&>@;: for 11 bytes.
This is a pure J verb which functions similarly to the other J answer, but instead of manually repeating * by the shape of each word, this answer applies the constant '*' to each cell of each word (aka each character) via rank-0 application "0, saving a byte.
APL, 13 bytes
↑'*'/⍨¨⊆⍨' '≠
Explanation
↑'*'/⍨¨⊆⍨' '≠
' '≠ ⍝ Find which chars are not spaces
⊆⍨ ⍝ and partition that with itself to get as many 1's as letters per word
'*'/⍨ ⍝ Apply replicate on '*', switching the args
¨ ⍝ on each array
↑ ⍝ Mix into a matrix
Vyxal, 5 bytes
⌈ꜝ@×*
This is pretty much exactly the same as my v2.4.1 answer just with two golfier builtins.
⌈ # Split on spaces
ꜝ # Remove empty strings
@ # Get length of each
* # Repeat that many times
× # "*"
Vyxal 3 -j, 5 bytes
Ṃl•×Ω
split on spaces, multiply the literal "*" by vectorized length, filter lambda gets truthy items to remove empty strings
Perl 5 + -p040l012, 6 bytes
y//*/c
Perl 5 + -n040F -M5.10.0, 9 bytes
say"*"x@F
Perl 5 + -p, 15 bytes
y/ /
/s;s/./*/g
Rockstar, 67 bytes
listen to S
cut S with " "
while S
roll S in W
if W
cut W
say "*"*W
Try it (Code will need to be pasted in)
listen to S :Read input and store in variable S
cut S with " " :Split S on spaces
while S :While S has length
roll S in W : Pop the first element and store in variable W
if W : If W is truthy (not an empty string)
cut W : Split W
say "*"*W : Output a "*" repeated length of W times, with trailing newline
Japt -R, 6 bytes
¸ËçÑÃf
¸ËçÑÃf :Implicit input of string
¸ :Split on spaces
Ë :Map
ç : Fill with
Ñ : "*"
à :End map
f :Filter
:Implicit output joined with newlines
Javascript (ES6)
New solution (39 bytes):
s=>[...s].map(c=>c==' '?`
`:'*').join``
Regex solution (42 bytes):
s=>s.replace(/\S/g,"*").replace(/ +/g,`
`)
Non-regex solution (71 bytes):
s=>s.split(" ").map(v=>"*".repeat(v.length)).filter(a=>a!="").join(`
`)
These solutions define anonymous functions. Assign them to variables or call them like so:
(s=>s.replace(/\S/g,"*").replace(/ +/g,`
`))("[your string here]")
(s=>s.split(" ").map(v=>"*".repeat(v.length)).filter(a=>a!="").join(`
`))("[your string here]")
Beam, 92 Bytes
This isn't a competitive answer at all and really quite late, but I've been playing around with Beam a bit lately and wanted to see if I could get it to do this. Finally got some success:)
'''''''>`++++++)v
vgLsP-(---`<''P'<
>rnp+v
>Sv>++v
(>`v+
H^ )+
^Sp`@p'<+
^ @++++<
var ITERS_PER_SEC = 100000;
var TIMEOUT_SECS = 50;
var ERROR_INTERRUPT = "Interrupted by user";
var ERROR_TIMEOUT = "Maximum iterations exceeded";
var ERROR_LOSTINSPACE = "Beam is lost in space";
var code, store, beam, ip_x, ip_y, dir, input_ptr, mem;
var input, timeout, width, iterations, running;
function clear_output() {
document.getElementById("output").value = "";
document.getElementById("stderr").innerHTML = "";
}
function stop() {
running = false;
document.getElementById("run").disabled = false;
document.getElementById("stop").disabled = true;
document.getElementById("clear").disabled = false;
document.getElementById("timeout").disabled = false;
}
function interrupt() {
error(ERROR_INTERRUPT);
}
function error(msg) {
document.getElementById("stderr").innerHTML = msg;
stop();
}
function run() {
clear_output();
document.getElementById("run").disabled = true;
document.getElementById("stop").disabled = false;
document.getElementById("clear").disabled = true;
document.getElementById("input").disabled = false;
document.getElementById("timeout").disabled = false;
code = document.getElementById("code").value;
input = document.getElementById("input").value;
timeout = document.getElementById("timeout").checked;
code = code.split("\n");
width = 0;
for (var i = 0; i < code.length; ++i){
if (code[i].length > width){
width = code[i].length;
}
}
console.log(code);
console.log(width);
running = true;
dir = 0;
ip_x = 0;
ip_y = 0;
input_ptr = 0;
beam = 0;
store = 0;
mem = [];
input = input.split("").map(function (s) {
return s.charCodeAt(0);
});
iterations = 0;
beam_iter();
}
function beam_iter() {
while (running) {
var inst;
try {
inst = code[ip_y][ip_x];
}
catch(err) {
inst = "";
}
switch (inst) {
case ">":
dir = 0;
break;
case "<":
dir = 1;
break;
case "^":
dir = 2;
break;
case "v":
dir = 3;
break;
case "+":
++beam;
break;
case "-":
--beam;
break;
case "@":
document.getElementById("output").value += String.fromCharCode(beam);
break;
case ":":
document.getElementById("output").value += beam+"\n";
break;
case "/":
switch (dir) {
case 0:
dir = 2;
break;
case 1:
dir = 3;
break;
case 2:
dir = 0;
break;
case 3:
dir = 1;
break;
}
case "\\":
switch (dir) {
case 0:
dir = 3;
break;
case 1:
dir = 2;
break;
case 2:
dir = 1;
break;
case 3:
dir = 0;
break;
}
break;
case "!":
if (beam != 0) {
switch (dir) {
case 0:
dir = 1;
break;
case 1:
dir = 0;
break;
case 2:
dir = 3;
break;
case 3:
dir = 2;
break;
}
}
break;
case "?":
if (beam == 0) {
switch (dir) {
case 0:
dir = 1;
break;
case 1:
dir = 0;
break;
case 2:
dir = 3;
break;
case 3:
dir = 2;
break;
}
}
break;
case "|":
switch (dir) {
case 0:
dir = 1;
break;
case 1:
dir = 0;
break;
}
break;
case "_":
switch (dir) {
case 0:
dir = 1;
break;
case 1:
dir = 0;
break;
}
break;
case "H":
stop();
break;
case "S":
store = beam;
break;
case "L":
beam = store;
break;
case "s":
mem[beam] = store;
break;
case "g":
store = mem[beam];
break;
case "P":
mem[store] = beam;
break;
case "p":
beam = mem[store];
break;
case "u":
if (beam != store) {
dir = 2;
}
break;
case "n":
if (beam != store) {
dir = 3;
}
break;
case "`":
--store;
break;
case "'":
++store;
break;
case ")":
if (store != 0) {
dir = 1;
}
break;
case "(":
if (store != 0) {
dir = 0;
}
break;
case "r":
if (input_ptr >= input.length) {
beam = 0;
} else
{
beam = input[input_ptr];
++input_ptr;
}
break;
}
// Move instruction pointer
switch (dir) {
case 0:
ip_x++;
break;
case 1:
ip_x--;
break;
case 2:
ip_y--;
break;
case 3:
ip_y++;
break;
}
if (running && (ip_x < 0 || ip_y < 0 || ip_x >= width || ip_y >= code.length)) {
error(ERROR_LOSTINSPACE);
}
++iterations;
if (iterations > ITERS_PER_SEC * TIMEOUT_SECS) {
error(ERROR_TIMEOUT);
}
}
}
<div style="font-size:12px;font-family:Verdana, Geneva, sans-serif;">Code:
<br>
<textarea id="code" rows="4" style="overflow:scroll;overflow-x:hidden;width:90%;">'''''''>`++++++)v
vgLsP-(---`<''P'<
>rnp+v
>Sv>++v
(>`v+
H^ )+
^Sp`@p'<+
^ @++++<
</textarea>
<br>Input:
<br>
<textarea id="input" rows="2" style="overflow:scroll;overflow-x:hidden;width:90%;">This is an example histogram of word length</textarea>
<p>Timeout:
<input id="timeout" type="checkbox" checked="checked">
<br>
<br>
<input id="run" type="button" value="Run" onclick="run()">
<input id="stop" type="button" value="Stop" onclick="interrupt()" disabled="disabled">
<input id="clear" type="button" value="Clear" onclick="clear_output()"> <span id="stderr" style="color:red"></span>
</p>Output:
<br>
<textarea id="output" rows="6" style="overflow:scroll;width:90%;"></textarea>
</div>
O, 22 bytes
i' /rl{e{'.'*%p}{;}?}d
Explanation
i Read the user input
' /r Split on spaces and reverse
l{ }d For each element
e ? If it's not empty
{'.'*% Replace every char with an asterick
p} And print it
{;} Else, just pop it off the stack
K5, 31 bytes
`0:{(#x)#"*"}'f@&0<#:'f:" "\0:`
PHP 5.3, 55 53 51 50 bytes
<?for(;$i<strlen($a);){echo$a{$i++}!=' '?'*':"
";}
Usage:
Call the Script and define a global variable ($a)
php -d error_reporting=0 script.php?a="This is an example histogram of word length"
Output:
****
**
**
*******
*********
**
****
******
sed - 20 bytes
s/[^ ]/*/g;s/ +/\n/g
~ $ sed -re 's/[^ ]/*/g;s/ +/\n/g' <<< 'This is an example histogram of word length'
****
**
**
*******
*********
**
****
******
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.
Ruby, 29 bytes
puts gets.gsub(/\S/,?*).split
J, 10 bytes
'*'$~$&>;:'This is an example histogram of word length'
****
**
**
*******
*********
**
****
******
Bonus: vertical (12 bytes)
|:'*'$~$&>;:'This is an example histogram of word length'
********
********
* ** **
* ** **
** *
** *
**
*
*
Bonus: flipped vertical (14 bytes)
|.|:'*'$~$&>;:'This is an example histogram of word length'
*
*
**
** *
** *
* ** **
* ** **
********
********
AWK
awk '{for(i=1;i<=NF;i++){while(k++<length($i)){printf "*"};k=0;print ""}}'
examples
echo "this is programming" | awk '{for(i=1;i<=NF;i++){while(k++<length($i)){printf "*"};k=0;print ""}}'
output:-
****
**
***********
Retina, 5 + 3 = 8 bytes
+
\n
.
*
Every line goes in its own file, so I've added 1 byte for each additional file. Also, the \n should be replaced with an actual newline.
Each pair of lines is a pattern-replacement pair. + matches one or more spaces and replaces it with a newline. . matches any character except a newline, and it replaces that with a *. This is applied globally, so every character is replaced with a *.
PowerShell, 35 31 Bytes
Pretty competitive for a change. Go go gadget unary operators. I also keep forgetting that parens on some functions, like the -split and -replace used here, are optional.
%{$_-split"\s+"-replace".","*"}
Called via pipeline input (equivalent to stdin for PowerShell):
PS C:\Tools\Scripts\golfing> "a aa aaa" | %{$_-split"\s+"-replace".","*"}
*
**
***
As a bonus, if we can instead use command-line arguments, we can get down to 20 Bytes and have something that works both with and without a single-string as input:
$args-replace".","*"
PS C:\Tools\Scripts\golfing> .\horizontal-graph-word-length.ps1 "double space example"
******
*****
*******
PS C:\Tools\Scripts\golfing> .\horizontal-graph-word-length.ps1 double space example
******
*****
*******
Matlab / Octave, 75 bytes
Using an anonymous function:
@(s)char(arrayfun(@(n)repmat('*',1,n),diff([0 find([s 32]==32)])-1,'un',0))
Thanks to Hoki for spotting a mistake which prevented the last word from being detected.
Example use (Matlab):
>> @(s)char(arrayfun(@(n)repmat('*',1,n),diff([0 find([s 32]==32)])-1,'un',0)) % define function
ans =
@(s)char(arrayfun(@(n)repmat('*',1,n),diff([0,find([s,32]==32)])-1,'un',0))
>> ans('This is an example histogram of word length') % call function
ans =
****
**
**
*******
*********
**
****
******
Or try it online (Octave).
Matlab - 54 bytes
s=input('');o=repmat('*',1,numel(s));o(s==32)=char(10)
This runs from the console, will take a string in input from stdin and will output the horizontal word graph in stdout:
Exemple:
>> s=input('');o=repmat('*',1,numel(s));o(s==32)=char(10)
'This is an example histogram of word length'
o =
****
**
**
*******
*********
**
****
******
Or we could try to make some fancy shapes:
>> s=input('');o=repmat('*',1,numel(s));o(s==32)=char(10)
'a aa aaa aaaaaa aaaaaaaaaa aaaaaaaaaaa aaaaaaaaaa aaaaaa aaa aa a aa aaa aaaaaa aaaaaaaaaa'
o =
*
**
***
******
**********
***********
**********
******
***
**
*
**
***
******
**********
JavaScript (ES5)
Program, 54 chars
alert(prompt().replace(/\S/g,'*').replace(/ +/g,'\n'))
Function, 60 chars
function(i){return i.replace(/\S/g,'*').replace(/ +/g,'\n')}
Example usage:
var h=function(i){return i.replace(/\S/g,'*').replace(/ +/g,'\n')},
d=document,g=d.getElementById.bind(d),i=g('i'),o=g('o')
i.onchange=function(){o.textContent=h(i.value)}
<input id="i"/>
<pre id="o"></pre>
JavaScript (ES6), 37
f=s=>s.replace(/./g,m=>m<"!"?`
`:'*')
Shorter version using only one replace.
Python 3, 43 bytes:
for w in input().split():print('*'*len(w))
Thanks to @BetaDecay for pointing out a syntax error.
Sample run:
> This is an example histogram of word length
****
**
**
*******
*********
**
****
******
(The string below is entered as a literal, rather than as text)
> 'example\twith\nweird\rwhite space'
*******
****
*****
**********
Bonus: vertical histogram
Thanks to @Caridorc for pointing out my error that made the bonuses have 1 to many rows.
l=[len(x)for x in input().split()]
for i in range(len(l)-1,0,-1):print(''.join(['*'if j>=i else' 'for j in l]))
Demo:
> This is an example histogram of word length
**
** *
** *
* ** **
* ** **
********
********
Bonus: vertical histogram (upside down)
l=[len(x)for x in input().split()]
for i in range(len(l)-1):print(''.join(['*'if j>i else' 'for j in l]))
Demo:
> This is an example histogram of word length
********
********
* ** **
* ** **
** *
** *
**
Javascript ES6
Function, 46 chars
f=s=>s.replace(/\S/g,'*').replace(/\s+/g,'\n')
Program, 55 chars
alert(prompt().replace(/\S/g,"*").replace(/\s+/g,"\n"))
Julia, 50 bytes
s->print(join(["*"^length(w)for w=split(s)],"\n"))
This creates an unnamed function that takes a string as input and prints to STDOUT.
Ungolfed:
function f(s::String)
# Construct a vector of horizontal bars
bars = ["*"^length(w) for w in split(s)]
# Join the bars with newlines
j = join(bars, "\n")
# Print the result to STDOUT
print(j)
end
><>, 38 37 Bytes
Curse you double space case *shakes fish*.
<v&0
>i:84*=?v0(?;67*o&1&
\ &0o?&a/
You can try it online (all you need to do is give input through the field near the bottom and then hit the Give button). Suggestions for further golfing are always welcome, especially ideas to remove those wasteful spaces in front of the second and third lines.
If you were allowed to print an additional newline for extra spaces, the code could be a whopping 27 bytes:
>i:84*=?v0(?;67*o
^ oa<
Explanation
Note: the order of the explanation will correspond to the pointer's location (so if the code is explained out of what one would consider order, it is because it is the order in which the pointer executes it).
Line 1:
<v&0
< redirects flow leftward
0 pushes 0 onto the stack
& pops 0 and puts it in the register
v redirects flow downward
Line 2:
>i:84*=?v0(?;67*o&1&
> redirects flow leftward
i: pushes input and then duplicates it
84* pushes 32 (the space character numerically)
=?v pops 32 and input and redirects flow downward if they're equal
0(?; pops input and terminates if input is less than 0*
67*o pushes 42 (asterisk) and prints it
&1& pushes register value and then puts 1 in the register
*in ><>, the command i returns -1 if no input is given
Line 3:
N.B. This line goes in reverse, so read right to left.
^ &0o?&a<
< redirects flow leftward
a pushes 10 (newline) onto the stack
o?& prints a newline if the register is not 0
&0 sets the register to 0
^ redirects flow upwards (back to the second line)
Basically, the program test to make sure the input (which is read one character at a time) is not a space and then prints an asterisk. It terminates if there is no input (the input value is -1). To make sure it doesn't print additional newlines, it uses the register value, which it either sets to 0 or 1. Because of the way I set it up, it doesn't care about the extraneous values pushed onto the stack (e.g. the value of the register when it sets it to 1 after printing an asterisk); they remain on the stack when the program terminates but do nothing.
I know it might be a bit confusing since I used 84* and 67* instead of " " and "*" respectively, but that was because I didn't feel like putting strings in the program for whatever reason.
CJam, 11 bytes
Competing for second place in CJam after @Optimizer found a clever 10 byte solution. This is a straightforward 11 byte solution:
lS%:,'*f*N*
Alternate solution that uses a loop instead of the two maps, also 11 bytes:
lS%{,'**N}/
Explanation for first solution:
l Get input.
S% Split at spaces.
:, Apply length operator to each word.
'*f* Map each length to corresponding repetitions of '*.
N* Join with newlines.
R - 33
write(gsub(".","*",scan(,"")),"")
where
scan(,"")reads from stdin and splits on white-space into a character vector.gsub(".", "*", ...)replaces all characters into*.write(..., "")prints to stdout with "\n" as the default separator.
Haskell, 31 bytes
putStr.unlines.map(>>"*").words
Usage example:
Main> putStr.unlines.map(>>"*").words $ "This is an example histogram of word length"
****
**
**
*******
*********
**
****
******
C++14, 107 106 bytes
#include<iostream>
main(){std::string s;for(;std::cin>>s;){for(char c:s)std::cout<<'*';std::cout<<'\n';}}
Gema, 11 9 characters
=\n
?=\*
Sample run:
bash-4.3$ gema ' =\n;?=\*' <<< 'This is an example histogram of word length'
****
**
**
*******
*********
**
****
******
bash-4.3$ gema ' =\n;?=\*' <<< 'a aa aaa aaaa aaaaa'
*
**
***
****
*****
bash-4.3$ gema ' =\n;?=\*' <<< 'double space example'
******
*****
*******
STATA, 72 bytes
di _r(a)
token "$a"
while ("`1'")!=""{
di _d(`=length("`1'")')"*"
ma s
}
Ungolfed
display _request(a) //get input via prompt
tokenize "$a" //split a by spaces into the variables 1,2,...
while ("`1'")!=""{ //while the first variable is not empty
display _dup(`=length("`1'")')"*" //display "*" duplicated for every character in variable 1.
macro shift //move variable 2 to 1, 3 to 2, etc.
}
Note that this code does not work in the online interpreter and requires the non-free proprietary STATA interpreter.
R, 38 bytes (with some help in comments)
cat(gsub(" +|$","\n",gsub("\\S","*",x)))
How it works
gsubreplaces all no-spaces with*- second
gsubadds\n(newline) to the end of each element catprints accordingly
Java, 102 bytes
class R{public static void main(String[]a){for(String s:a)System.out.println(s.replaceAll(".","*"));}}
Python 3, 72 bytes
A nice one liner :)
print(''.join(map(lambda x:"*"*len(x)+"\n"*int(x!=""),input().split())))
Output:
>>> print(''.join(map(lambda x:"*"*len(x)+"\n"*int(x!=""),input().split())))
Hello world how are you?
*****
*****
***
***
****
There's a trailing newline here. If you want it without, you've got to add 5 bytes:
print(''.join(map(lambda x:"*"*len(x)+"\n"*int(x!=""),input().split()))[:-1])
SWI-Prolog, 40 bytes
a([A|T]):-(A=32,nl;put(42)),(T=[];a(T)).
Called with code strings, e.g. a(`This is an example histogram of word length`).
Pyth, 9 bytes
jm*ld\*cz
Explanation:
jm*ld\*cz
cz chop input on whitespace
m map to
ld length of the segment
* \* number of asterisks
j joined on newlines
CJam, 10 bytes
r{,'**Nr}h
How it works:
r{ r}h e# This do-while loop basically reads all the whitespace separated tokens
e# from input. It separates the tokens on running lengths of whitespace
, e# Take the length of the token
'** e# Get a string of that many '*' characters
N e# Print a new line