Helloellolloloo Worldorldrldldd
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
Make a program that takes the word you input, and adds that word to the back of itself minus its first letter, then repeats until all letters are gone. For example, cat
would become catatt
, and hello
would become helloellolloloo
.
Input
Any of the 26 letters of the English alphabet. There may be multiple words separated by spaces, and the change should be applied to every word.
Output
The word(s) inputted, with each word put after itself with its first letter missing, and then with its second letter missing, and so on until there are no more letters to add.
More examples:
ill eel
outputs illlll eelell
laser bat
outputs laserasersererr batatt
darth vader
outputs dartharthrththh vaderaderdererr
This is code golf, so the shortest code wins.
code-golf string
New contributor
add a comment |Â
up vote
3
down vote
favorite
Make a program that takes the word you input, and adds that word to the back of itself minus its first letter, then repeats until all letters are gone. For example, cat
would become catatt
, and hello
would become helloellolloloo
.
Input
Any of the 26 letters of the English alphabet. There may be multiple words separated by spaces, and the change should be applied to every word.
Output
The word(s) inputted, with each word put after itself with its first letter missing, and then with its second letter missing, and so on until there are no more letters to add.
More examples:
ill eel
outputs illlll eelell
laser bat
outputs laserasersererr batatt
darth vader
outputs dartharthrththh vaderaderdererr
This is code golf, so the shortest code wins.
code-golf string
New contributor
2
honestly, the multiple words thing is kinda annoying. All it does is require a split, apply the function on each word, and then join again. It's also quite debilitating for lots of esolangs which have to check for a space manually
â Jo King
28 mins ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Make a program that takes the word you input, and adds that word to the back of itself minus its first letter, then repeats until all letters are gone. For example, cat
would become catatt
, and hello
would become helloellolloloo
.
Input
Any of the 26 letters of the English alphabet. There may be multiple words separated by spaces, and the change should be applied to every word.
Output
The word(s) inputted, with each word put after itself with its first letter missing, and then with its second letter missing, and so on until there are no more letters to add.
More examples:
ill eel
outputs illlll eelell
laser bat
outputs laserasersererr batatt
darth vader
outputs dartharthrththh vaderaderdererr
This is code golf, so the shortest code wins.
code-golf string
New contributor
Make a program that takes the word you input, and adds that word to the back of itself minus its first letter, then repeats until all letters are gone. For example, cat
would become catatt
, and hello
would become helloellolloloo
.
Input
Any of the 26 letters of the English alphabet. There may be multiple words separated by spaces, and the change should be applied to every word.
Output
The word(s) inputted, with each word put after itself with its first letter missing, and then with its second letter missing, and so on until there are no more letters to add.
More examples:
ill eel
outputs illlll eelell
laser bat
outputs laserasersererr batatt
darth vader
outputs dartharthrththh vaderaderdererr
This is code golf, so the shortest code wins.
code-golf string
code-golf string
New contributor
New contributor
edited 11 mins ago
W W
33.7k10148351
33.7k10148351
New contributor
asked 48 mins ago
qazwsx
16216
16216
New contributor
New contributor
2
honestly, the multiple words thing is kinda annoying. All it does is require a split, apply the function on each word, and then join again. It's also quite debilitating for lots of esolangs which have to check for a space manually
â Jo King
28 mins ago
add a comment |Â
2
honestly, the multiple words thing is kinda annoying. All it does is require a split, apply the function on each word, and then join again. It's also quite debilitating for lots of esolangs which have to check for a space manually
â Jo King
28 mins ago
2
2
honestly, the multiple words thing is kinda annoying. All it does is require a split, apply the function on each word, and then join again. It's also quite debilitating for lots of esolangs which have to check for a space manually
â Jo King
28 mins ago
honestly, the multiple words thing is kinda annoying. All it does is require a split, apply the function on each word, and then join again. It's also quite debilitating for lots of esolangs which have to check for a space manually
â Jo King
28 mins ago
add a comment |Â
8 Answers
8
active
oldest
votes
up vote
2
down vote
MATL, 18 bytes
Yb"@gXH"HX@Jh)]0&h
Try it online!
add a comment |Â
up vote
2
down vote
Haskell, 36 bytes
unwords.map(concat.scanr(:)"").words
Try it online!
add a comment |Â
up vote
1
down vote
Perl -p
, 36 25 bytes
s!b|[^ ]!$'=~s/ .*//r!eg
Try it online!
This is a single regsub. First, it matches all word boundaries or non-space characters:
[H][e][l][l][o] [W][o][r][l][d]
Note that each of these matches should be replaced with the rest of the word:
[âÂÂHello][HâÂÂello][eâÂÂllo][lâÂÂlo][lâÂÂo][oâÂÂ] (...)
We can accomplish this with the special variable $'
, which stores the part of the string after the match. However, we need to apply the nested regsub s/ .*//
to it, which removes everything past the first space in $'
, in order to get rid of the remaining words in the input.
add a comment |Â
up vote
1
down vote
R, 82 bytes
cat(sapply(scan(,""),function(s,y=nchar(s))paste(substring(s,1:y,y),collapse="")))
Try it online!
scan
by default splits on whitespace, so we get that for free, and cat
prints with sep=" "
, so we get that for free, too. The only thing that costs us a lot is the collapse=""
argument to paste
.
add a comment |Â
up vote
1
down vote
JavaScript (ES6), 45 bytes
s=>s.replace(/S+/g,g=s=>s?s+g(s.slice(1)):s)
Try it online!
JavaScript (ES6), 46 bytes
s=>s.replace(/S+/g,s=>s.replace(/./g,"$&$'"))
Try it online!
add a comment |Â
up vote
1
down vote
Japt -S
, 6 bytes
øÃÂãDsY
Try it
Without handling multiple words, this would be half the size: ãsY
Explanation
ø :Split on spaces
ÃÂ :Map each word D
ã : Map each letter at 0-based index Y
DsY : Slice D from index Y
:Implicitly join with spaces
add a comment |Â
up vote
0
down vote
C (gcc), 94 bytes
f(char*s)char*e=s+strlen(s),*i=s;for(;i<e;*i++=*i-32?*i:0);for(i=s;i<e;i++)printf(*i?i:" ");
Try it online!
Saves a pointer to the end of the string in char *e
, then replaces spaces with null characters, then prints the string starting with each character and ending at the next null character, but printing a space if the current character is a null character.
add a comment |Â
up vote
0
down vote
Python 3, 79 bytes
lambda y:' '.join(map(lambda x:''.join(x[n:]for n in range(len(x))),y.split()))
Try it online!
An anonymous lambda that takes a string and returns a string.
add a comment |Â
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
MATL, 18 bytes
Yb"@gXH"HX@Jh)]0&h
Try it online!
add a comment |Â
up vote
2
down vote
MATL, 18 bytes
Yb"@gXH"HX@Jh)]0&h
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
MATL, 18 bytes
Yb"@gXH"HX@Jh)]0&h
Try it online!
MATL, 18 bytes
Yb"@gXH"HX@Jh)]0&h
Try it online!
answered 29 mins ago
Luis Mendo
72.6k885284
72.6k885284
add a comment |Â
add a comment |Â
up vote
2
down vote
Haskell, 36 bytes
unwords.map(concat.scanr(:)"").words
Try it online!
add a comment |Â
up vote
2
down vote
Haskell, 36 bytes
unwords.map(concat.scanr(:)"").words
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Haskell, 36 bytes
unwords.map(concat.scanr(:)"").words
Try it online!
Haskell, 36 bytes
unwords.map(concat.scanr(:)"").words
Try it online!
edited 17 mins ago
answered 22 mins ago
nimi
29.9k31881
29.9k31881
add a comment |Â
add a comment |Â
up vote
1
down vote
Perl -p
, 36 25 bytes
s!b|[^ ]!$'=~s/ .*//r!eg
Try it online!
This is a single regsub. First, it matches all word boundaries or non-space characters:
[H][e][l][l][o] [W][o][r][l][d]
Note that each of these matches should be replaced with the rest of the word:
[âÂÂHello][HâÂÂello][eâÂÂllo][lâÂÂlo][lâÂÂo][oâÂÂ] (...)
We can accomplish this with the special variable $'
, which stores the part of the string after the match. However, we need to apply the nested regsub s/ .*//
to it, which removes everything past the first space in $'
, in order to get rid of the remaining words in the input.
add a comment |Â
up vote
1
down vote
Perl -p
, 36 25 bytes
s!b|[^ ]!$'=~s/ .*//r!eg
Try it online!
This is a single regsub. First, it matches all word boundaries or non-space characters:
[H][e][l][l][o] [W][o][r][l][d]
Note that each of these matches should be replaced with the rest of the word:
[âÂÂHello][HâÂÂello][eâÂÂllo][lâÂÂlo][lâÂÂo][oâÂÂ] (...)
We can accomplish this with the special variable $'
, which stores the part of the string after the match. However, we need to apply the nested regsub s/ .*//
to it, which removes everything past the first space in $'
, in order to get rid of the remaining words in the input.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Perl -p
, 36 25 bytes
s!b|[^ ]!$'=~s/ .*//r!eg
Try it online!
This is a single regsub. First, it matches all word boundaries or non-space characters:
[H][e][l][l][o] [W][o][r][l][d]
Note that each of these matches should be replaced with the rest of the word:
[âÂÂHello][HâÂÂello][eâÂÂllo][lâÂÂlo][lâÂÂo][oâÂÂ] (...)
We can accomplish this with the special variable $'
, which stores the part of the string after the match. However, we need to apply the nested regsub s/ .*//
to it, which removes everything past the first space in $'
, in order to get rid of the remaining words in the input.
Perl -p
, 36 25 bytes
s!b|[^ ]!$'=~s/ .*//r!eg
Try it online!
This is a single regsub. First, it matches all word boundaries or non-space characters:
[H][e][l][l][o] [W][o][r][l][d]
Note that each of these matches should be replaced with the rest of the word:
[âÂÂHello][HâÂÂello][eâÂÂllo][lâÂÂlo][lâÂÂo][oâÂÂ] (...)
We can accomplish this with the special variable $'
, which stores the part of the string after the match. However, we need to apply the nested regsub s/ .*//
to it, which removes everything past the first space in $'
, in order to get rid of the remaining words in the input.
edited 19 mins ago
answered 33 mins ago
Doorknobâ¦
53.5k16111339
53.5k16111339
add a comment |Â
add a comment |Â
up vote
1
down vote
R, 82 bytes
cat(sapply(scan(,""),function(s,y=nchar(s))paste(substring(s,1:y,y),collapse="")))
Try it online!
scan
by default splits on whitespace, so we get that for free, and cat
prints with sep=" "
, so we get that for free, too. The only thing that costs us a lot is the collapse=""
argument to paste
.
add a comment |Â
up vote
1
down vote
R, 82 bytes
cat(sapply(scan(,""),function(s,y=nchar(s))paste(substring(s,1:y,y),collapse="")))
Try it online!
scan
by default splits on whitespace, so we get that for free, and cat
prints with sep=" "
, so we get that for free, too. The only thing that costs us a lot is the collapse=""
argument to paste
.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
R, 82 bytes
cat(sapply(scan(,""),function(s,y=nchar(s))paste(substring(s,1:y,y),collapse="")))
Try it online!
scan
by default splits on whitespace, so we get that for free, and cat
prints with sep=" "
, so we get that for free, too. The only thing that costs us a lot is the collapse=""
argument to paste
.
R, 82 bytes
cat(sapply(scan(,""),function(s,y=nchar(s))paste(substring(s,1:y,y),collapse="")))
Try it online!
scan
by default splits on whitespace, so we get that for free, and cat
prints with sep=" "
, so we get that for free, too. The only thing that costs us a lot is the collapse=""
argument to paste
.
edited 17 mins ago
answered 25 mins ago
Giuseppe
14.9k31049
14.9k31049
add a comment |Â
add a comment |Â
up vote
1
down vote
JavaScript (ES6), 45 bytes
s=>s.replace(/S+/g,g=s=>s?s+g(s.slice(1)):s)
Try it online!
JavaScript (ES6), 46 bytes
s=>s.replace(/S+/g,s=>s.replace(/./g,"$&$'"))
Try it online!
add a comment |Â
up vote
1
down vote
JavaScript (ES6), 45 bytes
s=>s.replace(/S+/g,g=s=>s?s+g(s.slice(1)):s)
Try it online!
JavaScript (ES6), 46 bytes
s=>s.replace(/S+/g,s=>s.replace(/./g,"$&$'"))
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
JavaScript (ES6), 45 bytes
s=>s.replace(/S+/g,g=s=>s?s+g(s.slice(1)):s)
Try it online!
JavaScript (ES6), 46 bytes
s=>s.replace(/S+/g,s=>s.replace(/./g,"$&$'"))
Try it online!
JavaScript (ES6), 45 bytes
s=>s.replace(/S+/g,g=s=>s?s+g(s.slice(1)):s)
Try it online!
JavaScript (ES6), 46 bytes
s=>s.replace(/S+/g,s=>s.replace(/./g,"$&$'"))
Try it online!
answered 12 mins ago
Arnauld
64.3k580270
64.3k580270
add a comment |Â
add a comment |Â
up vote
1
down vote
Japt -S
, 6 bytes
øÃÂãDsY
Try it
Without handling multiple words, this would be half the size: ãsY
Explanation
ø :Split on spaces
ÃÂ :Map each word D
ã : Map each letter at 0-based index Y
DsY : Slice D from index Y
:Implicitly join with spaces
add a comment |Â
up vote
1
down vote
Japt -S
, 6 bytes
øÃÂãDsY
Try it
Without handling multiple words, this would be half the size: ãsY
Explanation
ø :Split on spaces
ÃÂ :Map each word D
ã : Map each letter at 0-based index Y
DsY : Slice D from index Y
:Implicitly join with spaces
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Japt -S
, 6 bytes
øÃÂãDsY
Try it
Without handling multiple words, this would be half the size: ãsY
Explanation
ø :Split on spaces
ÃÂ :Map each word D
ã : Map each letter at 0-based index Y
DsY : Slice D from index Y
:Implicitly join with spaces
Japt -S
, 6 bytes
øÃÂãDsY
Try it
Without handling multiple words, this would be half the size: ãsY
Explanation
ø :Split on spaces
ÃÂ :Map each word D
ã : Map each letter at 0-based index Y
DsY : Slice D from index Y
:Implicitly join with spaces
edited 4 mins ago
answered 17 mins ago
Shaggy
16.4k21560
16.4k21560
add a comment |Â
add a comment |Â
up vote
0
down vote
C (gcc), 94 bytes
f(char*s)char*e=s+strlen(s),*i=s;for(;i<e;*i++=*i-32?*i:0);for(i=s;i<e;i++)printf(*i?i:" ");
Try it online!
Saves a pointer to the end of the string in char *e
, then replaces spaces with null characters, then prints the string starting with each character and ending at the next null character, but printing a space if the current character is a null character.
add a comment |Â
up vote
0
down vote
C (gcc), 94 bytes
f(char*s)char*e=s+strlen(s),*i=s;for(;i<e;*i++=*i-32?*i:0);for(i=s;i<e;i++)printf(*i?i:" ");
Try it online!
Saves a pointer to the end of the string in char *e
, then replaces spaces with null characters, then prints the string starting with each character and ending at the next null character, but printing a space if the current character is a null character.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
C (gcc), 94 bytes
f(char*s)char*e=s+strlen(s),*i=s;for(;i<e;*i++=*i-32?*i:0);for(i=s;i<e;i++)printf(*i?i:" ");
Try it online!
Saves a pointer to the end of the string in char *e
, then replaces spaces with null characters, then prints the string starting with each character and ending at the next null character, but printing a space if the current character is a null character.
C (gcc), 94 bytes
f(char*s)char*e=s+strlen(s),*i=s;for(;i<e;*i++=*i-32?*i:0);for(i=s;i<e;i++)printf(*i?i:" ");
Try it online!
Saves a pointer to the end of the string in char *e
, then replaces spaces with null characters, then prints the string starting with each character and ending at the next null character, but printing a space if the current character is a null character.
answered 11 mins ago
pizzapants184
2,474716
2,474716
add a comment |Â
add a comment |Â
up vote
0
down vote
Python 3, 79 bytes
lambda y:' '.join(map(lambda x:''.join(x[n:]for n in range(len(x))),y.split()))
Try it online!
An anonymous lambda that takes a string and returns a string.
add a comment |Â
up vote
0
down vote
Python 3, 79 bytes
lambda y:' '.join(map(lambda x:''.join(x[n:]for n in range(len(x))),y.split()))
Try it online!
An anonymous lambda that takes a string and returns a string.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Python 3, 79 bytes
lambda y:' '.join(map(lambda x:''.join(x[n:]for n in range(len(x))),y.split()))
Try it online!
An anonymous lambda that takes a string and returns a string.
Python 3, 79 bytes
lambda y:' '.join(map(lambda x:''.join(x[n:]for n in range(len(x))),y.split()))
Try it online!
An anonymous lambda that takes a string and returns a string.
answered 4 mins ago
Jo King
15.5k24087
15.5k24087
add a comment |Â
add a comment |Â
qazwsx is a new contributor. Be nice, and check out our Code of Conduct.
qazwsx is a new contributor. Be nice, and check out our Code of Conduct.
qazwsx is a new contributor. Be nice, and check out our Code of Conduct.
qazwsx is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172391%2fhelloellolloloo-worldorldrldldd%23new-answer', 'question_page');
);
Post as a guest
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
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
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
2
honestly, the multiple words thing is kinda annoying. All it does is require a split, apply the function on each word, and then join again. It's also quite debilitating for lots of esolangs which have to check for a space manually
â Jo King
28 mins ago