Make it rain characters
$begingroup$
Inspired by this chat mini-challenge.
Given a string as input (ASCII printable characters only), output the string with the letters "raining" down. Each letter must be a random number of lines downward (random between 0
and the length of the string, each having non-zero probability), and only one character per column. All possible outputs must again have a non-zero probability of occurring.
That's maybe a little confusing, so here's an example (taken from that CMC):
Hello World
d
H
o
llo
l
W
e
r
Note how the H
is one space down, the d
is zero down, and the llo
all happen to line up. The r
is the farthest down, at 9
, but is still less than the string length away from the top. This is just one example, there are dozens of other possibilities for input Hello World
.
Other examples could be:
test
t
e
s
t
PP&CG
& G
P
P C
- Input and output can be given by any convenient method.
- The input is guaranteed non-empty (i.e., you'll never receive
""
as input). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately (e.g., feel free to pad as a rectangle).
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf string ascii-art
$endgroup$
add a comment |
$begingroup$
Inspired by this chat mini-challenge.
Given a string as input (ASCII printable characters only), output the string with the letters "raining" down. Each letter must be a random number of lines downward (random between 0
and the length of the string, each having non-zero probability), and only one character per column. All possible outputs must again have a non-zero probability of occurring.
That's maybe a little confusing, so here's an example (taken from that CMC):
Hello World
d
H
o
llo
l
W
e
r
Note how the H
is one space down, the d
is zero down, and the llo
all happen to line up. The r
is the farthest down, at 9
, but is still less than the string length away from the top. This is just one example, there are dozens of other possibilities for input Hello World
.
Other examples could be:
test
t
e
s
t
PP&CG
& G
P
P C
- Input and output can be given by any convenient method.
- The input is guaranteed non-empty (i.e., you'll never receive
""
as input). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately (e.g., feel free to pad as a rectangle).
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf string ascii-art
$endgroup$
$begingroup$
Thought this was going to involve animation when I read the title. Have we had an animated version of this?
$endgroup$
– Shaggy
3 hours ago
$begingroup$
@Shaggy Not that I've seen or been able to find.
$endgroup$
– AdmBorkBork
1 hour ago
add a comment |
$begingroup$
Inspired by this chat mini-challenge.
Given a string as input (ASCII printable characters only), output the string with the letters "raining" down. Each letter must be a random number of lines downward (random between 0
and the length of the string, each having non-zero probability), and only one character per column. All possible outputs must again have a non-zero probability of occurring.
That's maybe a little confusing, so here's an example (taken from that CMC):
Hello World
d
H
o
llo
l
W
e
r
Note how the H
is one space down, the d
is zero down, and the llo
all happen to line up. The r
is the farthest down, at 9
, but is still less than the string length away from the top. This is just one example, there are dozens of other possibilities for input Hello World
.
Other examples could be:
test
t
e
s
t
PP&CG
& G
P
P C
- Input and output can be given by any convenient method.
- The input is guaranteed non-empty (i.e., you'll never receive
""
as input). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately (e.g., feel free to pad as a rectangle).
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf string ascii-art
$endgroup$
Inspired by this chat mini-challenge.
Given a string as input (ASCII printable characters only), output the string with the letters "raining" down. Each letter must be a random number of lines downward (random between 0
and the length of the string, each having non-zero probability), and only one character per column. All possible outputs must again have a non-zero probability of occurring.
That's maybe a little confusing, so here's an example (taken from that CMC):
Hello World
d
H
o
llo
l
W
e
r
Note how the H
is one space down, the d
is zero down, and the llo
all happen to line up. The r
is the farthest down, at 9
, but is still less than the string length away from the top. This is just one example, there are dozens of other possibilities for input Hello World
.
Other examples could be:
test
t
e
s
t
PP&CG
& G
P
P C
- Input and output can be given by any convenient method.
- The input is guaranteed non-empty (i.e., you'll never receive
""
as input). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately (e.g., feel free to pad as a rectangle).
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf string ascii-art
code-golf string ascii-art
asked 12 hours ago
AdmBorkBorkAdmBorkBork
27.9k467241
27.9k467241
$begingroup$
Thought this was going to involve animation when I read the title. Have we had an animated version of this?
$endgroup$
– Shaggy
3 hours ago
$begingroup$
@Shaggy Not that I've seen or been able to find.
$endgroup$
– AdmBorkBork
1 hour ago
add a comment |
$begingroup$
Thought this was going to involve animation when I read the title. Have we had an animated version of this?
$endgroup$
– Shaggy
3 hours ago
$begingroup$
@Shaggy Not that I've seen or been able to find.
$endgroup$
– AdmBorkBork
1 hour ago
$begingroup$
Thought this was going to involve animation when I read the title. Have we had an animated version of this?
$endgroup$
– Shaggy
3 hours ago
$begingroup$
Thought this was going to involve animation when I read the title. Have we had an animated version of this?
$endgroup$
– Shaggy
3 hours ago
$begingroup$
@Shaggy Not that I've seen or been able to find.
$endgroup$
– AdmBorkBork
1 hour ago
$begingroup$
@Shaggy Not that I've seen or been able to find.
$endgroup$
– AdmBorkBork
1 hour ago
add a comment |
12 Answers
12
active
oldest
votes
$begingroup$
R, 104 bytes
function(s){m=matrix(" ",l<-nchar(s),l)
m[cbind(1:l,sample(l,l,T))]=el(strsplit(s,""))
write(m,1,l,,"")}
Try it online!
Input as a string; writes to stdout.
$endgroup$
$begingroup$
You can save a byte by usingscan(,'')
and nesting a bunch of calls but honestly I vastly prefer the function approach, this other one is hideous for minimal gain. Might spark some ideas, though. Try it online!
$endgroup$
– CriminallyVulgar
11 hours ago
$begingroup$
I thinksample(l,,T)
suffices instead ofsample(l,l,T)
(-1 byte).
$endgroup$
– Robin Ryder
10 hours ago
add a comment |
$begingroup$
Pyth - 9 bytes
Outputs list of lines.
.tm+*;OlQ
.t Transpose, padding with spaces
m (Q implicit) Map over input
+ (d implicit) Concatenate to loop var
* String repeat
; This refers to the var replaced by loop var, which is d=" "
O Random number less than
lQ Length of input
Try it online.
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 16 bytesSBCS
Anonymous tacit prefix function
⍉∘↑⊢↑¨⍨∘-∘?≢⍴1+≢
≢
length of string
1+
one added to that
≢⍴
"length" copies of that
∘?
random integers in range 1…those, and then…
∘-
negate, and then…
⊢↑¨⍨
take than many elements from each character, padding on the left with spaces
∘↑
mix list of strings into matrix, padding with spaces on the right
⍉
transpose
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 59 57 bytes
->a{a.map{|c|s=[' ']*z=a.size;[s[rand z]=c]+s}.transpose}
Try it online!
Inputs 1D, outputs 2D array of characters.
$endgroup$
add a comment |
$begingroup$
Japt, 8 bytes
-1 byte from @Shaggy
y_iUÊö ç
y_iUÊö ç Full Program. Implicit input U
y_ transpose and map each row in U (Call it X)
i Insert at the beginning of X:
ç " " repeated ↓ many times
UÊö random integer in [0, length of U]
implicit transpose back and output
Try it online!
$endgroup$
1
$begingroup$
8 bytes
$endgroup$
– Shaggy
11 hours ago
$begingroup$
lol @Shaggy I got the same answer a while ago, i was just adding an explanation. Thanks anyway c:
$endgroup$
– Luis felipe De jesus Munoz
11 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 72 bytes
Takes input as a list of characters. Returns a matrix of characters.
a=>a.map((_,y)=>a.map((c,x)=>Math.random()<.5|!a[y+1]?(a[x]=' ',c):' '))
Try it online!
$endgroup$
$begingroup$
I think you could save one byte by not negating the ternary expression.
$endgroup$
– orthoplex
12 hours ago
2
$begingroup$
@orthoplex That wouldn't work because(0|'A') === (0|undefined)
and the remaining letters would not be guaranteed anymore to appear on the last row. (So, basically, it's just like|!a[y+1]
was removed altogether.)
$endgroup$
– Arnauld
12 hours ago
add a comment |
$begingroup$
J, 30 19 bytes
|:@,.]{.~"+_2-#?@##
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt, 8 bytes
yÈùUÊö Ä
Try it
yÈùUÊö Ä :Implicit input of string U
y :Transpose
È :Pass each column through the following function and transpose back
ù : Left pad with spaces to length
UÊ : Length of U
ö : Random number in the range [0,UÊ)
Ä : Plus 1
$endgroup$
add a comment |
$begingroup$
PHP, 88 bytes
for($o='';$i<$l=strlen($argn);$o[$i+$l*rand(0,$l)]=$argn[$i++]);echo chunk_split($o,$l);
Try it online!
Input from STDIN
, output to STDOUT
. Run as:
$ echo Hello World|php -nF rain.php
l W
l
e r d
H o
l
o
-1 byte (empty string instead of space) and +1 byte (err on side of rules) thx to @ASCII-only!
$endgroup$
$begingroup$
wonder if this is allowed, since you don't include the<?php
that the?>
closes. also seems like it's fine if$o
is the empty string
$endgroup$
– ASCII-only
2 hours ago
$begingroup$
@ASCII-only, you're right, empty string will also work (with a little more complaining). I'm not sure the ruling on using closing and re-opening tags, I'll update it though to stay on the up and up. Thx!
$endgroup$
– gwaugh
2 hours ago
add a comment |
$begingroup$
Python - 78 bytes
lambda s:map(None,*[(random.randrange(len(s))*' '+c).ljust(len(s))for c in s])
$endgroup$
$begingroup$
You have to include theimport random
$endgroup$
– MilkyWay90
3 hours ago
add a comment |
$begingroup$
Jelly, 10 bytes
³LŻX⁶x;)z⁶
Try it online!
) | For each input character
³L | Length of original input
Ż | 0..length
X | Random number from that list
⁶x | That number of spaces
; | Concatenate to the character
z⁶ | Finally transpose with space as filler
$endgroup$
add a comment |
$begingroup$
Charcoal, 10 9 bytes
↑Eθ◧ι⊕‽Lθ
Try it online! Link is to verbose version of code. Edit: Saved 1 byte thanks to @ASCII-only. Explanation:
θ Input string
E Map over characters
θ Input string
L Length
‽ Random value
⊕ Incremented
ι Current character
◧ Padded to length
↑ Print rotated
As ASCII-only points out, you can move the letters randomly up instead of down for the same effect (except that there might be extra white space at the bottom rather than the top). Printing an array of characters upwards is equivalent to printing a string normally, so the padding then just offsets each character vertically by a random amount.
$endgroup$
$begingroup$
wonder if printing up instead would work?
$endgroup$
– ASCII-only
2 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f183066%2fmake-it-rain-characters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
12 Answers
12
active
oldest
votes
12 Answers
12
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
R, 104 bytes
function(s){m=matrix(" ",l<-nchar(s),l)
m[cbind(1:l,sample(l,l,T))]=el(strsplit(s,""))
write(m,1,l,,"")}
Try it online!
Input as a string; writes to stdout.
$endgroup$
$begingroup$
You can save a byte by usingscan(,'')
and nesting a bunch of calls but honestly I vastly prefer the function approach, this other one is hideous for minimal gain. Might spark some ideas, though. Try it online!
$endgroup$
– CriminallyVulgar
11 hours ago
$begingroup$
I thinksample(l,,T)
suffices instead ofsample(l,l,T)
(-1 byte).
$endgroup$
– Robin Ryder
10 hours ago
add a comment |
$begingroup$
R, 104 bytes
function(s){m=matrix(" ",l<-nchar(s),l)
m[cbind(1:l,sample(l,l,T))]=el(strsplit(s,""))
write(m,1,l,,"")}
Try it online!
Input as a string; writes to stdout.
$endgroup$
$begingroup$
You can save a byte by usingscan(,'')
and nesting a bunch of calls but honestly I vastly prefer the function approach, this other one is hideous for minimal gain. Might spark some ideas, though. Try it online!
$endgroup$
– CriminallyVulgar
11 hours ago
$begingroup$
I thinksample(l,,T)
suffices instead ofsample(l,l,T)
(-1 byte).
$endgroup$
– Robin Ryder
10 hours ago
add a comment |
$begingroup$
R, 104 bytes
function(s){m=matrix(" ",l<-nchar(s),l)
m[cbind(1:l,sample(l,l,T))]=el(strsplit(s,""))
write(m,1,l,,"")}
Try it online!
Input as a string; writes to stdout.
$endgroup$
R, 104 bytes
function(s){m=matrix(" ",l<-nchar(s),l)
m[cbind(1:l,sample(l,l,T))]=el(strsplit(s,""))
write(m,1,l,,"")}
Try it online!
Input as a string; writes to stdout.
edited 12 hours ago
answered 12 hours ago
GiuseppeGiuseppe
17.8k31153
17.8k31153
$begingroup$
You can save a byte by usingscan(,'')
and nesting a bunch of calls but honestly I vastly prefer the function approach, this other one is hideous for minimal gain. Might spark some ideas, though. Try it online!
$endgroup$
– CriminallyVulgar
11 hours ago
$begingroup$
I thinksample(l,,T)
suffices instead ofsample(l,l,T)
(-1 byte).
$endgroup$
– Robin Ryder
10 hours ago
add a comment |
$begingroup$
You can save a byte by usingscan(,'')
and nesting a bunch of calls but honestly I vastly prefer the function approach, this other one is hideous for minimal gain. Might spark some ideas, though. Try it online!
$endgroup$
– CriminallyVulgar
11 hours ago
$begingroup$
I thinksample(l,,T)
suffices instead ofsample(l,l,T)
(-1 byte).
$endgroup$
– Robin Ryder
10 hours ago
$begingroup$
You can save a byte by using
scan(,'')
and nesting a bunch of calls but honestly I vastly prefer the function approach, this other one is hideous for minimal gain. Might spark some ideas, though. Try it online!$endgroup$
– CriminallyVulgar
11 hours ago
$begingroup$
You can save a byte by using
scan(,'')
and nesting a bunch of calls but honestly I vastly prefer the function approach, this other one is hideous for minimal gain. Might spark some ideas, though. Try it online!$endgroup$
– CriminallyVulgar
11 hours ago
$begingroup$
I think
sample(l,,T)
suffices instead of sample(l,l,T)
(-1 byte).$endgroup$
– Robin Ryder
10 hours ago
$begingroup$
I think
sample(l,,T)
suffices instead of sample(l,l,T)
(-1 byte).$endgroup$
– Robin Ryder
10 hours ago
add a comment |
$begingroup$
Pyth - 9 bytes
Outputs list of lines.
.tm+*;OlQ
.t Transpose, padding with spaces
m (Q implicit) Map over input
+ (d implicit) Concatenate to loop var
* String repeat
; This refers to the var replaced by loop var, which is d=" "
O Random number less than
lQ Length of input
Try it online.
$endgroup$
add a comment |
$begingroup$
Pyth - 9 bytes
Outputs list of lines.
.tm+*;OlQ
.t Transpose, padding with spaces
m (Q implicit) Map over input
+ (d implicit) Concatenate to loop var
* String repeat
; This refers to the var replaced by loop var, which is d=" "
O Random number less than
lQ Length of input
Try it online.
$endgroup$
add a comment |
$begingroup$
Pyth - 9 bytes
Outputs list of lines.
.tm+*;OlQ
.t Transpose, padding with spaces
m (Q implicit) Map over input
+ (d implicit) Concatenate to loop var
* String repeat
; This refers to the var replaced by loop var, which is d=" "
O Random number less than
lQ Length of input
Try it online.
$endgroup$
Pyth - 9 bytes
Outputs list of lines.
.tm+*;OlQ
.t Transpose, padding with spaces
m (Q implicit) Map over input
+ (d implicit) Concatenate to loop var
* String repeat
; This refers to the var replaced by loop var, which is d=" "
O Random number less than
lQ Length of input
Try it online.
edited 11 hours ago
answered 12 hours ago
MaltysenMaltysen
21.4k445116
21.4k445116
add a comment |
add a comment |
$begingroup$
APL (Dyalog Unicode), 16 bytesSBCS
Anonymous tacit prefix function
⍉∘↑⊢↑¨⍨∘-∘?≢⍴1+≢
≢
length of string
1+
one added to that
≢⍴
"length" copies of that
∘?
random integers in range 1…those, and then…
∘-
negate, and then…
⊢↑¨⍨
take than many elements from each character, padding on the left with spaces
∘↑
mix list of strings into matrix, padding with spaces on the right
⍉
transpose
Try it online!
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 16 bytesSBCS
Anonymous tacit prefix function
⍉∘↑⊢↑¨⍨∘-∘?≢⍴1+≢
≢
length of string
1+
one added to that
≢⍴
"length" copies of that
∘?
random integers in range 1…those, and then…
∘-
negate, and then…
⊢↑¨⍨
take than many elements from each character, padding on the left with spaces
∘↑
mix list of strings into matrix, padding with spaces on the right
⍉
transpose
Try it online!
$endgroup$
add a comment |
$begingroup$
APL (Dyalog Unicode), 16 bytesSBCS
Anonymous tacit prefix function
⍉∘↑⊢↑¨⍨∘-∘?≢⍴1+≢
≢
length of string
1+
one added to that
≢⍴
"length" copies of that
∘?
random integers in range 1…those, and then…
∘-
negate, and then…
⊢↑¨⍨
take than many elements from each character, padding on the left with spaces
∘↑
mix list of strings into matrix, padding with spaces on the right
⍉
transpose
Try it online!
$endgroup$
APL (Dyalog Unicode), 16 bytesSBCS
Anonymous tacit prefix function
⍉∘↑⊢↑¨⍨∘-∘?≢⍴1+≢
≢
length of string
1+
one added to that
≢⍴
"length" copies of that
∘?
random integers in range 1…those, and then…
∘-
negate, and then…
⊢↑¨⍨
take than many elements from each character, padding on the left with spaces
∘↑
mix list of strings into matrix, padding with spaces on the right
⍉
transpose
Try it online!
edited 12 hours ago
answered 12 hours ago
AdámAdám
28.6k276207
28.6k276207
add a comment |
add a comment |
$begingroup$
Ruby, 59 57 bytes
->a{a.map{|c|s=[' ']*z=a.size;[s[rand z]=c]+s}.transpose}
Try it online!
Inputs 1D, outputs 2D array of characters.
$endgroup$
add a comment |
$begingroup$
Ruby, 59 57 bytes
->a{a.map{|c|s=[' ']*z=a.size;[s[rand z]=c]+s}.transpose}
Try it online!
Inputs 1D, outputs 2D array of characters.
$endgroup$
add a comment |
$begingroup$
Ruby, 59 57 bytes
->a{a.map{|c|s=[' ']*z=a.size;[s[rand z]=c]+s}.transpose}
Try it online!
Inputs 1D, outputs 2D array of characters.
$endgroup$
Ruby, 59 57 bytes
->a{a.map{|c|s=[' ']*z=a.size;[s[rand z]=c]+s}.transpose}
Try it online!
Inputs 1D, outputs 2D array of characters.
edited 12 hours ago
answered 12 hours ago
Kirill L.Kirill L.
6,1281527
6,1281527
add a comment |
add a comment |
$begingroup$
Japt, 8 bytes
-1 byte from @Shaggy
y_iUÊö ç
y_iUÊö ç Full Program. Implicit input U
y_ transpose and map each row in U (Call it X)
i Insert at the beginning of X:
ç " " repeated ↓ many times
UÊö random integer in [0, length of U]
implicit transpose back and output
Try it online!
$endgroup$
1
$begingroup$
8 bytes
$endgroup$
– Shaggy
11 hours ago
$begingroup$
lol @Shaggy I got the same answer a while ago, i was just adding an explanation. Thanks anyway c:
$endgroup$
– Luis felipe De jesus Munoz
11 hours ago
add a comment |
$begingroup$
Japt, 8 bytes
-1 byte from @Shaggy
y_iUÊö ç
y_iUÊö ç Full Program. Implicit input U
y_ transpose and map each row in U (Call it X)
i Insert at the beginning of X:
ç " " repeated ↓ many times
UÊö random integer in [0, length of U]
implicit transpose back and output
Try it online!
$endgroup$
1
$begingroup$
8 bytes
$endgroup$
– Shaggy
11 hours ago
$begingroup$
lol @Shaggy I got the same answer a while ago, i was just adding an explanation. Thanks anyway c:
$endgroup$
– Luis felipe De jesus Munoz
11 hours ago
add a comment |
$begingroup$
Japt, 8 bytes
-1 byte from @Shaggy
y_iUÊö ç
y_iUÊö ç Full Program. Implicit input U
y_ transpose and map each row in U (Call it X)
i Insert at the beginning of X:
ç " " repeated ↓ many times
UÊö random integer in [0, length of U]
implicit transpose back and output
Try it online!
$endgroup$
Japt, 8 bytes
-1 byte from @Shaggy
y_iUÊö ç
y_iUÊö ç Full Program. Implicit input U
y_ transpose and map each row in U (Call it X)
i Insert at the beginning of X:
ç " " repeated ↓ many times
UÊö random integer in [0, length of U]
implicit transpose back and output
Try it online!
edited 11 hours ago
answered 11 hours ago
Luis felipe De jesus MunozLuis felipe De jesus Munoz
5,72821671
5,72821671
1
$begingroup$
8 bytes
$endgroup$
– Shaggy
11 hours ago
$begingroup$
lol @Shaggy I got the same answer a while ago, i was just adding an explanation. Thanks anyway c:
$endgroup$
– Luis felipe De jesus Munoz
11 hours ago
add a comment |
1
$begingroup$
8 bytes
$endgroup$
– Shaggy
11 hours ago
$begingroup$
lol @Shaggy I got the same answer a while ago, i was just adding an explanation. Thanks anyway c:
$endgroup$
– Luis felipe De jesus Munoz
11 hours ago
1
1
$begingroup$
8 bytes
$endgroup$
– Shaggy
11 hours ago
$begingroup$
8 bytes
$endgroup$
– Shaggy
11 hours ago
$begingroup$
lol @Shaggy I got the same answer a while ago, i was just adding an explanation. Thanks anyway c:
$endgroup$
– Luis felipe De jesus Munoz
11 hours ago
$begingroup$
lol @Shaggy I got the same answer a while ago, i was just adding an explanation. Thanks anyway c:
$endgroup$
– Luis felipe De jesus Munoz
11 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 72 bytes
Takes input as a list of characters. Returns a matrix of characters.
a=>a.map((_,y)=>a.map((c,x)=>Math.random()<.5|!a[y+1]?(a[x]=' ',c):' '))
Try it online!
$endgroup$
$begingroup$
I think you could save one byte by not negating the ternary expression.
$endgroup$
– orthoplex
12 hours ago
2
$begingroup$
@orthoplex That wouldn't work because(0|'A') === (0|undefined)
and the remaining letters would not be guaranteed anymore to appear on the last row. (So, basically, it's just like|!a[y+1]
was removed altogether.)
$endgroup$
– Arnauld
12 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 72 bytes
Takes input as a list of characters. Returns a matrix of characters.
a=>a.map((_,y)=>a.map((c,x)=>Math.random()<.5|!a[y+1]?(a[x]=' ',c):' '))
Try it online!
$endgroup$
$begingroup$
I think you could save one byte by not negating the ternary expression.
$endgroup$
– orthoplex
12 hours ago
2
$begingroup$
@orthoplex That wouldn't work because(0|'A') === (0|undefined)
and the remaining letters would not be guaranteed anymore to appear on the last row. (So, basically, it's just like|!a[y+1]
was removed altogether.)
$endgroup$
– Arnauld
12 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 72 bytes
Takes input as a list of characters. Returns a matrix of characters.
a=>a.map((_,y)=>a.map((c,x)=>Math.random()<.5|!a[y+1]?(a[x]=' ',c):' '))
Try it online!
$endgroup$
JavaScript (ES6), 72 bytes
Takes input as a list of characters. Returns a matrix of characters.
a=>a.map((_,y)=>a.map((c,x)=>Math.random()<.5|!a[y+1]?(a[x]=' ',c):' '))
Try it online!
answered 12 hours ago
ArnauldArnauld
80.9k797334
80.9k797334
$begingroup$
I think you could save one byte by not negating the ternary expression.
$endgroup$
– orthoplex
12 hours ago
2
$begingroup$
@orthoplex That wouldn't work because(0|'A') === (0|undefined)
and the remaining letters would not be guaranteed anymore to appear on the last row. (So, basically, it's just like|!a[y+1]
was removed altogether.)
$endgroup$
– Arnauld
12 hours ago
add a comment |
$begingroup$
I think you could save one byte by not negating the ternary expression.
$endgroup$
– orthoplex
12 hours ago
2
$begingroup$
@orthoplex That wouldn't work because(0|'A') === (0|undefined)
and the remaining letters would not be guaranteed anymore to appear on the last row. (So, basically, it's just like|!a[y+1]
was removed altogether.)
$endgroup$
– Arnauld
12 hours ago
$begingroup$
I think you could save one byte by not negating the ternary expression.
$endgroup$
– orthoplex
12 hours ago
$begingroup$
I think you could save one byte by not negating the ternary expression.
$endgroup$
– orthoplex
12 hours ago
2
2
$begingroup$
@orthoplex That wouldn't work because
(0|'A') === (0|undefined)
and the remaining letters would not be guaranteed anymore to appear on the last row. (So, basically, it's just like |!a[y+1]
was removed altogether.)$endgroup$
– Arnauld
12 hours ago
$begingroup$
@orthoplex That wouldn't work because
(0|'A') === (0|undefined)
and the remaining letters would not be guaranteed anymore to appear on the last row. (So, basically, it's just like |!a[y+1]
was removed altogether.)$endgroup$
– Arnauld
12 hours ago
add a comment |
$begingroup$
J, 30 19 bytes
|:@,.]{.~"+_2-#?@##
Try it online!
$endgroup$
add a comment |
$begingroup$
J, 30 19 bytes
|:@,.]{.~"+_2-#?@##
Try it online!
$endgroup$
add a comment |
$begingroup$
J, 30 19 bytes
|:@,.]{.~"+_2-#?@##
Try it online!
$endgroup$
J, 30 19 bytes
|:@,.]{.~"+_2-#?@##
Try it online!
edited 11 hours ago
answered 11 hours ago
Conor O'BrienConor O'Brien
30.7k264162
30.7k264162
add a comment |
add a comment |
$begingroup$
Japt, 8 bytes
yÈùUÊö Ä
Try it
yÈùUÊö Ä :Implicit input of string U
y :Transpose
È :Pass each column through the following function and transpose back
ù : Left pad with spaces to length
UÊ : Length of U
ö : Random number in the range [0,UÊ)
Ä : Plus 1
$endgroup$
add a comment |
$begingroup$
Japt, 8 bytes
yÈùUÊö Ä
Try it
yÈùUÊö Ä :Implicit input of string U
y :Transpose
È :Pass each column through the following function and transpose back
ù : Left pad with spaces to length
UÊ : Length of U
ö : Random number in the range [0,UÊ)
Ä : Plus 1
$endgroup$
add a comment |
$begingroup$
Japt, 8 bytes
yÈùUÊö Ä
Try it
yÈùUÊö Ä :Implicit input of string U
y :Transpose
È :Pass each column through the following function and transpose back
ù : Left pad with spaces to length
UÊ : Length of U
ö : Random number in the range [0,UÊ)
Ä : Plus 1
$endgroup$
Japt, 8 bytes
yÈùUÊö Ä
Try it
yÈùUÊö Ä :Implicit input of string U
y :Transpose
È :Pass each column through the following function and transpose back
ù : Left pad with spaces to length
UÊ : Length of U
ö : Random number in the range [0,UÊ)
Ä : Plus 1
answered 11 hours ago
ShaggyShaggy
19k21768
19k21768
add a comment |
add a comment |
$begingroup$
PHP, 88 bytes
for($o='';$i<$l=strlen($argn);$o[$i+$l*rand(0,$l)]=$argn[$i++]);echo chunk_split($o,$l);
Try it online!
Input from STDIN
, output to STDOUT
. Run as:
$ echo Hello World|php -nF rain.php
l W
l
e r d
H o
l
o
-1 byte (empty string instead of space) and +1 byte (err on side of rules) thx to @ASCII-only!
$endgroup$
$begingroup$
wonder if this is allowed, since you don't include the<?php
that the?>
closes. also seems like it's fine if$o
is the empty string
$endgroup$
– ASCII-only
2 hours ago
$begingroup$
@ASCII-only, you're right, empty string will also work (with a little more complaining). I'm not sure the ruling on using closing and re-opening tags, I'll update it though to stay on the up and up. Thx!
$endgroup$
– gwaugh
2 hours ago
add a comment |
$begingroup$
PHP, 88 bytes
for($o='';$i<$l=strlen($argn);$o[$i+$l*rand(0,$l)]=$argn[$i++]);echo chunk_split($o,$l);
Try it online!
Input from STDIN
, output to STDOUT
. Run as:
$ echo Hello World|php -nF rain.php
l W
l
e r d
H o
l
o
-1 byte (empty string instead of space) and +1 byte (err on side of rules) thx to @ASCII-only!
$endgroup$
$begingroup$
wonder if this is allowed, since you don't include the<?php
that the?>
closes. also seems like it's fine if$o
is the empty string
$endgroup$
– ASCII-only
2 hours ago
$begingroup$
@ASCII-only, you're right, empty string will also work (with a little more complaining). I'm not sure the ruling on using closing and re-opening tags, I'll update it though to stay on the up and up. Thx!
$endgroup$
– gwaugh
2 hours ago
add a comment |
$begingroup$
PHP, 88 bytes
for($o='';$i<$l=strlen($argn);$o[$i+$l*rand(0,$l)]=$argn[$i++]);echo chunk_split($o,$l);
Try it online!
Input from STDIN
, output to STDOUT
. Run as:
$ echo Hello World|php -nF rain.php
l W
l
e r d
H o
l
o
-1 byte (empty string instead of space) and +1 byte (err on side of rules) thx to @ASCII-only!
$endgroup$
PHP, 88 bytes
for($o='';$i<$l=strlen($argn);$o[$i+$l*rand(0,$l)]=$argn[$i++]);echo chunk_split($o,$l);
Try it online!
Input from STDIN
, output to STDOUT
. Run as:
$ echo Hello World|php -nF rain.php
l W
l
e r d
H o
l
o
-1 byte (empty string instead of space) and +1 byte (err on side of rules) thx to @ASCII-only!
edited 2 hours ago
answered 5 hours ago
gwaughgwaugh
2,1481518
2,1481518
$begingroup$
wonder if this is allowed, since you don't include the<?php
that the?>
closes. also seems like it's fine if$o
is the empty string
$endgroup$
– ASCII-only
2 hours ago
$begingroup$
@ASCII-only, you're right, empty string will also work (with a little more complaining). I'm not sure the ruling on using closing and re-opening tags, I'll update it though to stay on the up and up. Thx!
$endgroup$
– gwaugh
2 hours ago
add a comment |
$begingroup$
wonder if this is allowed, since you don't include the<?php
that the?>
closes. also seems like it's fine if$o
is the empty string
$endgroup$
– ASCII-only
2 hours ago
$begingroup$
@ASCII-only, you're right, empty string will also work (with a little more complaining). I'm not sure the ruling on using closing and re-opening tags, I'll update it though to stay on the up and up. Thx!
$endgroup$
– gwaugh
2 hours ago
$begingroup$
wonder if this is allowed, since you don't include the
<?php
that the ?>
closes. also seems like it's fine if $o
is the empty string$endgroup$
– ASCII-only
2 hours ago
$begingroup$
wonder if this is allowed, since you don't include the
<?php
that the ?>
closes. also seems like it's fine if $o
is the empty string$endgroup$
– ASCII-only
2 hours ago
$begingroup$
@ASCII-only, you're right, empty string will also work (with a little more complaining). I'm not sure the ruling on using closing and re-opening tags, I'll update it though to stay on the up and up. Thx!
$endgroup$
– gwaugh
2 hours ago
$begingroup$
@ASCII-only, you're right, empty string will also work (with a little more complaining). I'm not sure the ruling on using closing and re-opening tags, I'll update it though to stay on the up and up. Thx!
$endgroup$
– gwaugh
2 hours ago
add a comment |
$begingroup$
Python - 78 bytes
lambda s:map(None,*[(random.randrange(len(s))*' '+c).ljust(len(s))for c in s])
$endgroup$
$begingroup$
You have to include theimport random
$endgroup$
– MilkyWay90
3 hours ago
add a comment |
$begingroup$
Python - 78 bytes
lambda s:map(None,*[(random.randrange(len(s))*' '+c).ljust(len(s))for c in s])
$endgroup$
$begingroup$
You have to include theimport random
$endgroup$
– MilkyWay90
3 hours ago
add a comment |
$begingroup$
Python - 78 bytes
lambda s:map(None,*[(random.randrange(len(s))*' '+c).ljust(len(s))for c in s])
$endgroup$
Python - 78 bytes
lambda s:map(None,*[(random.randrange(len(s))*' '+c).ljust(len(s))for c in s])
answered 11 hours ago
MaltysenMaltysen
21.4k445116
21.4k445116
$begingroup$
You have to include theimport random
$endgroup$
– MilkyWay90
3 hours ago
add a comment |
$begingroup$
You have to include theimport random
$endgroup$
– MilkyWay90
3 hours ago
$begingroup$
You have to include the
import random
$endgroup$
– MilkyWay90
3 hours ago
$begingroup$
You have to include the
import random
$endgroup$
– MilkyWay90
3 hours ago
add a comment |
$begingroup$
Jelly, 10 bytes
³LŻX⁶x;)z⁶
Try it online!
) | For each input character
³L | Length of original input
Ż | 0..length
X | Random number from that list
⁶x | That number of spaces
; | Concatenate to the character
z⁶ | Finally transpose with space as filler
$endgroup$
add a comment |
$begingroup$
Jelly, 10 bytes
³LŻX⁶x;)z⁶
Try it online!
) | For each input character
³L | Length of original input
Ż | 0..length
X | Random number from that list
⁶x | That number of spaces
; | Concatenate to the character
z⁶ | Finally transpose with space as filler
$endgroup$
add a comment |
$begingroup$
Jelly, 10 bytes
³LŻX⁶x;)z⁶
Try it online!
) | For each input character
³L | Length of original input
Ż | 0..length
X | Random number from that list
⁶x | That number of spaces
; | Concatenate to the character
z⁶ | Finally transpose with space as filler
$endgroup$
Jelly, 10 bytes
³LŻX⁶x;)z⁶
Try it online!
) | For each input character
³L | Length of original input
Ż | 0..length
X | Random number from that list
⁶x | That number of spaces
; | Concatenate to the character
z⁶ | Finally transpose with space as filler
answered 6 hours ago
Nick KennedyNick Kennedy
1,53649
1,53649
add a comment |
add a comment |
$begingroup$
Charcoal, 10 9 bytes
↑Eθ◧ι⊕‽Lθ
Try it online! Link is to verbose version of code. Edit: Saved 1 byte thanks to @ASCII-only. Explanation:
θ Input string
E Map over characters
θ Input string
L Length
‽ Random value
⊕ Incremented
ι Current character
◧ Padded to length
↑ Print rotated
As ASCII-only points out, you can move the letters randomly up instead of down for the same effect (except that there might be extra white space at the bottom rather than the top). Printing an array of characters upwards is equivalent to printing a string normally, so the padding then just offsets each character vertically by a random amount.
$endgroup$
$begingroup$
wonder if printing up instead would work?
$endgroup$
– ASCII-only
2 hours ago
add a comment |
$begingroup$
Charcoal, 10 9 bytes
↑Eθ◧ι⊕‽Lθ
Try it online! Link is to verbose version of code. Edit: Saved 1 byte thanks to @ASCII-only. Explanation:
θ Input string
E Map over characters
θ Input string
L Length
‽ Random value
⊕ Incremented
ι Current character
◧ Padded to length
↑ Print rotated
As ASCII-only points out, you can move the letters randomly up instead of down for the same effect (except that there might be extra white space at the bottom rather than the top). Printing an array of characters upwards is equivalent to printing a string normally, so the padding then just offsets each character vertically by a random amount.
$endgroup$
$begingroup$
wonder if printing up instead would work?
$endgroup$
– ASCII-only
2 hours ago
add a comment |
$begingroup$
Charcoal, 10 9 bytes
↑Eθ◧ι⊕‽Lθ
Try it online! Link is to verbose version of code. Edit: Saved 1 byte thanks to @ASCII-only. Explanation:
θ Input string
E Map over characters
θ Input string
L Length
‽ Random value
⊕ Incremented
ι Current character
◧ Padded to length
↑ Print rotated
As ASCII-only points out, you can move the letters randomly up instead of down for the same effect (except that there might be extra white space at the bottom rather than the top). Printing an array of characters upwards is equivalent to printing a string normally, so the padding then just offsets each character vertically by a random amount.
$endgroup$
Charcoal, 10 9 bytes
↑Eθ◧ι⊕‽Lθ
Try it online! Link is to verbose version of code. Edit: Saved 1 byte thanks to @ASCII-only. Explanation:
θ Input string
E Map over characters
θ Input string
L Length
‽ Random value
⊕ Incremented
ι Current character
◧ Padded to length
↑ Print rotated
As ASCII-only points out, you can move the letters randomly up instead of down for the same effect (except that there might be extra white space at the bottom rather than the top). Printing an array of characters upwards is equivalent to printing a string normally, so the padding then just offsets each character vertically by a random amount.
edited 1 hour ago
answered 7 hours ago
NeilNeil
82.8k745179
82.8k745179
$begingroup$
wonder if printing up instead would work?
$endgroup$
– ASCII-only
2 hours ago
add a comment |
$begingroup$
wonder if printing up instead would work?
$endgroup$
– ASCII-only
2 hours ago
$begingroup$
wonder if printing up instead would work?
$endgroup$
– ASCII-only
2 hours ago
$begingroup$
wonder if printing up instead would work?
$endgroup$
– ASCII-only
2 hours ago
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f183066%2fmake-it-rain-characters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Thought this was going to involve animation when I read the title. Have we had an animated version of this?
$endgroup$
– Shaggy
3 hours ago
$begingroup$
@Shaggy Not that I've seen or been able to find.
$endgroup$
– AdmBorkBork
1 hour ago