pwaS eht tirsf dna tasl setterl fo hace dorwThe world ends in ed“Hello world” that creates a different “Hello world” programWatson-Crick palindromesCheck if a pattern appears in a DNA sequencelwap She tirst fetters!Swep tha vowels!Swap letter and digit runsReduce string to a snippet of the alphabetCount Consecutive CharactersDoce logf a string swapper
Are spiritual pleasures > carnal pleasures, according to Catholicism?
Who is frowning in the sentence "Daisy looked at Tom frowning"?
In Dutch history two people are referred to as "William III"; are there any more cases where this happens?
Appropriate liquid/solvent for life in my underground environment on Venus
Why does the U.S military use mercenaries?
How can I monitor the bulk API limit?
What should I wear to go and sign an employment contract?
Why does a table with a defined constant in its index compute 10X slower?
How does this piece of code determine array size without using sizeof( )?
Does the US Supreme Court vote using secret ballots?
Will this series of events work to drown a tarrasque?
Can 2 light bulbs of 120V in series be used on 230V AC?
Have the writers and actors of GOT responded to its poor reception?
Why is so much ransomware breakable?
Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?
Have GoT's showrunners reacted to the poor reception of the final season?
Why is the S-duct intake on the Tu-154 uniquely oblong?
Would a "ring language" be possible?
Taylor series leads to two different functions - why?
How would fantasy dwarves exist, realistically?
How do you cope with rejection?
Should I twist DC power and ground wires from a power supply?
What's is the easiest way to purchase a stock and hold it
The underlying space of an affine open dense subscheme
pwaS eht tirsf dna tasl setterl fo hace dorw
The world ends in ed“Hello world” that creates a different “Hello world” programWatson-Crick palindromesCheck if a pattern appears in a DNA sequencelwap She tirst fetters!Swep tha vowels!Swap letter and digit runsReduce string to a snippet of the alphabetCount Consecutive CharactersDoce logf a string swapper
$begingroup$
Or, "Swap the first and last letters of each word"
Your challenge is to, given a string of alphabetical ASCII characters as well as one other character to use as a delimiter (to separate each word), swap the first and last letters of each word. If there is a one-character word, leave it alone.
The examples/testcases use the lowercase letters and the space as the delimiter.
You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, separated by spaces, all of a uniform case.
For example, with the string "hello world":
Input string: "hello world"
Identify each word: "[hello] [world]"
Identify the first and last letters of each word: "[[h]ell[o]] [[w]orl[d]]"
Swap the first letters of each word: "[[o]ell[h]] [[d]orl[w]]"
Final string: "oellh dorlw"
Test cases:
"swap the first and last letters of each word" -> "pwas eht tirsf dna tasl setterl fo hace dorw"
"hello world" -> "oellh dorlw"
"test cases" -> "test sasec"
"programming puzzles and code golf" -> "grogramminp suzzlep dna eodc folg"
"in a green meadow" -> "ni a nreeg weadom"
"yay racecar" -> "yay racecar"
code-golf string
$endgroup$
add a comment |
$begingroup$
Or, "Swap the first and last letters of each word"
Your challenge is to, given a string of alphabetical ASCII characters as well as one other character to use as a delimiter (to separate each word), swap the first and last letters of each word. If there is a one-character word, leave it alone.
The examples/testcases use the lowercase letters and the space as the delimiter.
You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, separated by spaces, all of a uniform case.
For example, with the string "hello world":
Input string: "hello world"
Identify each word: "[hello] [world]"
Identify the first and last letters of each word: "[[h]ell[o]] [[w]orl[d]]"
Swap the first letters of each word: "[[o]ell[h]] [[d]orl[w]]"
Final string: "oellh dorlw"
Test cases:
"swap the first and last letters of each word" -> "pwas eht tirsf dna tasl setterl fo hace dorw"
"hello world" -> "oellh dorlw"
"test cases" -> "test sasec"
"programming puzzles and code golf" -> "grogramminp suzzlep dna eodc folg"
"in a green meadow" -> "ni a nreeg weadom"
"yay racecar" -> "yay racecar"
code-golf string
$endgroup$
$begingroup$
How should punctuation be treated?Hello, world!becomes,elloH !orldw(swapping punctuation as a letter) oroellH, dorlw!(keeping punctuation in place)?
$endgroup$
– Phelype Oleinik
2 hours ago
$begingroup$
@PhelypeOleinik You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, and all a uniform case.
$endgroup$
– Comrade SparklePony
2 hours ago
2
$begingroup$
Second paragraph reads as well as one other character to use as a delimiter while the fourth reads separated by spaces. Which one is it?
$endgroup$
– Adám
1 hour ago
add a comment |
$begingroup$
Or, "Swap the first and last letters of each word"
Your challenge is to, given a string of alphabetical ASCII characters as well as one other character to use as a delimiter (to separate each word), swap the first and last letters of each word. If there is a one-character word, leave it alone.
The examples/testcases use the lowercase letters and the space as the delimiter.
You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, separated by spaces, all of a uniform case.
For example, with the string "hello world":
Input string: "hello world"
Identify each word: "[hello] [world]"
Identify the first and last letters of each word: "[[h]ell[o]] [[w]orl[d]]"
Swap the first letters of each word: "[[o]ell[h]] [[d]orl[w]]"
Final string: "oellh dorlw"
Test cases:
"swap the first and last letters of each word" -> "pwas eht tirsf dna tasl setterl fo hace dorw"
"hello world" -> "oellh dorlw"
"test cases" -> "test sasec"
"programming puzzles and code golf" -> "grogramminp suzzlep dna eodc folg"
"in a green meadow" -> "ni a nreeg weadom"
"yay racecar" -> "yay racecar"
code-golf string
$endgroup$
Or, "Swap the first and last letters of each word"
Your challenge is to, given a string of alphabetical ASCII characters as well as one other character to use as a delimiter (to separate each word), swap the first and last letters of each word. If there is a one-character word, leave it alone.
The examples/testcases use the lowercase letters and the space as the delimiter.
You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, separated by spaces, all of a uniform case.
For example, with the string "hello world":
Input string: "hello world"
Identify each word: "[hello] [world]"
Identify the first and last letters of each word: "[[h]ell[o]] [[w]orl[d]]"
Swap the first letters of each word: "[[o]ell[h]] [[d]orl[w]]"
Final string: "oellh dorlw"
Test cases:
"swap the first and last letters of each word" -> "pwas eht tirsf dna tasl setterl fo hace dorw"
"hello world" -> "oellh dorlw"
"test cases" -> "test sasec"
"programming puzzles and code golf" -> "grogramminp suzzlep dna eodc folg"
"in a green meadow" -> "ni a nreeg weadom"
"yay racecar" -> "yay racecar"
code-golf string
code-golf string
edited 2 hours ago
Magic Octopus Urn
13.1k444126
13.1k444126
asked 2 hours ago
Comrade SparklePonyComrade SparklePony
3,56111554
3,56111554
$begingroup$
How should punctuation be treated?Hello, world!becomes,elloH !orldw(swapping punctuation as a letter) oroellH, dorlw!(keeping punctuation in place)?
$endgroup$
– Phelype Oleinik
2 hours ago
$begingroup$
@PhelypeOleinik You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, and all a uniform case.
$endgroup$
– Comrade SparklePony
2 hours ago
2
$begingroup$
Second paragraph reads as well as one other character to use as a delimiter while the fourth reads separated by spaces. Which one is it?
$endgroup$
– Adám
1 hour ago
add a comment |
$begingroup$
How should punctuation be treated?Hello, world!becomes,elloH !orldw(swapping punctuation as a letter) oroellH, dorlw!(keeping punctuation in place)?
$endgroup$
– Phelype Oleinik
2 hours ago
$begingroup$
@PhelypeOleinik You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, and all a uniform case.
$endgroup$
– Comrade SparklePony
2 hours ago
2
$begingroup$
Second paragraph reads as well as one other character to use as a delimiter while the fourth reads separated by spaces. Which one is it?
$endgroup$
– Adám
1 hour ago
$begingroup$
How should punctuation be treated?
Hello, world! becomes ,elloH !orldw (swapping punctuation as a letter) or oellH, dorlw! (keeping punctuation in place)?$endgroup$
– Phelype Oleinik
2 hours ago
$begingroup$
How should punctuation be treated?
Hello, world! becomes ,elloH !orldw (swapping punctuation as a letter) or oellH, dorlw! (keeping punctuation in place)?$endgroup$
– Phelype Oleinik
2 hours ago
$begingroup$
@PhelypeOleinik You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, and all a uniform case.
$endgroup$
– Comrade SparklePony
2 hours ago
$begingroup$
@PhelypeOleinik You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, and all a uniform case.
$endgroup$
– Comrade SparklePony
2 hours ago
2
2
$begingroup$
Second paragraph reads as well as one other character to use as a delimiter while the fourth reads separated by spaces. Which one is it?
$endgroup$
– Adám
1 hour ago
$begingroup$
Second paragraph reads as well as one other character to use as a delimiter while the fourth reads separated by spaces. Which one is it?
$endgroup$
– Adám
1 hour ago
add a comment |
12 Answers
12
active
oldest
votes
$begingroup$
TeX, 220 bytes (5 lines, 44 characters each)
Because it's not about the byte count, it's about the quality of the typeset output :-)
HADD#%
1#2#3
Try it Online! (Overleaf; not sure how it works)
Full test file:
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
bye
Output:
For LaTeX you just need the boilerplate:
documentclassarticle
begindocument
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
enddocument
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 39 36 bytes
Saved 3 bytes thanks to @FryAmTheEggman
Uses a linefeed as separator.
s=>s.replace(/(.)(.*)(.)/g,'$3$2$1')
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 42 41+1 = 42 bytes
Add one byte for the p flag.
gsub(/w+/)$&.sub /(.)(.*)(.)/,'321'
Try it online!
$endgroup$
add a comment |
$begingroup$
05AB1E, 10 bytes
#vyRćsRćðJ
Try it online!
-3 Thanks to The Kevster.
# | Split into words.
vy | For each word...
RćsRć | Reverse, split head, swap, reverse, split tail
ðJ | Join by spaces.
$endgroup$
1
$begingroup$
10 bytes
$endgroup$
– Kevin Cruijssen
1 hour ago
1
$begingroup$
@KevinCruijssen I honestly want to delete it and give it to you, that was 99% your brainpower on the ordering of the arguments haha.
$endgroup$
– Magic Octopus Urn
59 mins ago
$begingroup$
The 100% brainpower only took a minute, so you can have it. ;p My initial approach was a map like this:#εRćsRćJ}ðý. And then I noticed your loop and thought that just pushing a space char and joining the entire stack would save a trailing}, hence the 10 byter. I have the feeling a 9-byter might be possible, though..
$endgroup$
– Kevin Cruijssen
40 mins ago
$begingroup$
Found a 9-byter, but it only works in the legacy version:|ʒRćsRćJ,
$endgroup$
– Kevin Cruijssen
18 mins ago
$begingroup$
Too bad we don't have aloop_as_long_as_there_are_inputs, then I would have known an 8-byter:[RćsRćJ,This 8-byter using[never outputs in theory however, only when you're out of memory or time out like on TIO (and it requires a trailing newline in the input, otherwise it will keep using the last word)..
$endgroup$
– Kevin Cruijssen
13 mins ago
add a comment |
$begingroup$
Python 3, 72 58 bytes
print(*[x[-1]+x[1:-1]+x[:x>x[0]]for x in input().split()])
Try it online!
$endgroup$
$begingroup$
Doesn't work for one letter words (ega)
$endgroup$
– TFeld
1 hour ago
$begingroup$
@TFeld, fixed..
$endgroup$
– alexz02
1 hour ago
add a comment |
$begingroup$
Retina, 8 5 bytes
,V,,`
Try it online!
Saved 3 bytes thanks to Kevin Cruijssen!
Uses a newline as the separator. We make use of Retina's reverse stage and some limits. The first limit is which matches to apply the reversal to, so we pick all of them with ,. Then we want the first and last letter of each match to be swapped, so we take each letter in the range ,, which translates to a range from the beginning to the end with step size zero.
$endgroup$
$begingroup$
Dangit, I was just searching through the docs for something like this to update my answer, but you beat me to it. I knew aboutV, but didn't knew it could be used with the indices1,-2like that. Nice one!
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@KevinCruijssen I cheated a little and reviewed how limit ranges worked while this was in the sandbox :) I still feel like there should be a better way than inverting a range but I haven't been able to find anything shorter.
$endgroup$
– FryAmTheEggman
1 hour ago
1
$begingroup$
You're indeed right that it can be shorter without a limit-range, because it seems this 5-byter works (given as example at the bottom of the Step Limits in the docs).
$endgroup$
– Kevin Cruijssen
47 mins ago
$begingroup$
@KevinCruijssen Nice! Can't believe I missed that.
$endgroup$
– FryAmTheEggman
37 mins ago
add a comment |
$begingroup$
QuadR, 20 bytes
(w)(w*)(w)
321
Simply make three capturing groups consisting of 1, 0-or-more, and 1 word-characters, then reverses their order.
Try it online!
$endgroup$
add a comment |
$begingroup$
Stax, 11 bytes
ô"┼▼φƒY╛»u~
Run and debug it
$endgroup$
add a comment |
$begingroup$
Python 2, 67 66 64 61 bytes
lambda s:' '.join(w[-1]+w[1:-1]+w[:w>w[0]]for w in s.split())
Try it online!
-1 byte, thanks to squid
Python 3, 63 61 58 bytes
print(*[w[-1]+w[1:-1]+w[:w>w[0]]for w in input().split()])
Try it online!
$endgroup$
$begingroup$
You can remove the whitespace before ">"
$endgroup$
– squid
1 hour ago
$begingroup$
@squid thanks. I'm on mobile, so whitespace is hard on tio.
$endgroup$
– TFeld
1 hour ago
$begingroup$
Your 58-byte version is now an exact (except for the variable name) copy of alexz02's latest edit from 20 minutes ago
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@kevincruijssen ergh.. To be fair, that answer is a trivial golf of my earlier edit...
$endgroup$
– TFeld
59 mins ago
2
$begingroup$
True. I was mentioning it merely as a FYI. :) There isn't any rule disqualifying duplicated answers when both users independently came to the same solutions.
$endgroup$
– Kevin Cruijssen
56 mins ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 92 bytes
StringRiffle[StringReplacePart[#,StringTake[#,1,-1],-1,-1,1,1]&/@StringSplit@#]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -p, 24 bytes
s/(w)(w*)(w)/$3$2$1/g
Try it online!
$endgroup$
add a comment |
$begingroup$
PHP, 73 bytes
foreach(explode(' ',$argn)as$w)[$w[0],$w[-1]]=[$w[-1],$w[0]];echo"$w ";
Try it online!
Using PHP 7.1's Square bracket syntax for array destructuring.
$endgroup$
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%2f185674%2fpwas-eht-tirsf-dna-tasl-setterl-fo-hace-dorw%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$
TeX, 220 bytes (5 lines, 44 characters each)
Because it's not about the byte count, it's about the quality of the typeset output :-)
HADD#%
1#2#3
Try it Online! (Overleaf; not sure how it works)
Full test file:
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
bye
Output:
For LaTeX you just need the boilerplate:
documentclassarticle
begindocument
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
enddocument
$endgroup$
add a comment |
$begingroup$
TeX, 220 bytes (5 lines, 44 characters each)
Because it's not about the byte count, it's about the quality of the typeset output :-)
HADD#%
1#2#3
Try it Online! (Overleaf; not sure how it works)
Full test file:
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
bye
Output:
For LaTeX you just need the boilerplate:
documentclassarticle
begindocument
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
enddocument
$endgroup$
add a comment |
$begingroup$
TeX, 220 bytes (5 lines, 44 characters each)
Because it's not about the byte count, it's about the quality of the typeset output :-)
HADD#%
1#2#3
Try it Online! (Overleaf; not sure how it works)
Full test file:
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
bye
Output:
For LaTeX you just need the boilerplate:
documentclassarticle
begindocument
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
enddocument
$endgroup$
TeX, 220 bytes (5 lines, 44 characters each)
Because it's not about the byte count, it's about the quality of the typeset output :-)
HADD#%
1#2#3
Try it Online! (Overleaf; not sure how it works)
Full test file:
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
bye
Output:
For LaTeX you just need the boilerplate:
documentclassarticle
begindocument
HADD#%
1#2#3
Sswap the a first and last letters of each word
pwas eht a tirsf dna tasl setterl fo hace dorw
SSWAP THE A FIRST AND LAST LETTERS OF EACH WORD
enddocument
edited 54 mins ago
answered 1 hour ago
Phelype OleinikPhelype Oleinik
395212
395212
add a comment |
add a comment |
$begingroup$
JavaScript (ES6), 39 36 bytes
Saved 3 bytes thanks to @FryAmTheEggman
Uses a linefeed as separator.
s=>s.replace(/(.)(.*)(.)/g,'$3$2$1')
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 39 36 bytes
Saved 3 bytes thanks to @FryAmTheEggman
Uses a linefeed as separator.
s=>s.replace(/(.)(.*)(.)/g,'$3$2$1')
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 39 36 bytes
Saved 3 bytes thanks to @FryAmTheEggman
Uses a linefeed as separator.
s=>s.replace(/(.)(.*)(.)/g,'$3$2$1')
Try it online!
$endgroup$
JavaScript (ES6), 39 36 bytes
Saved 3 bytes thanks to @FryAmTheEggman
Uses a linefeed as separator.
s=>s.replace(/(.)(.*)(.)/g,'$3$2$1')
Try it online!
edited 44 mins ago
answered 1 hour ago
ArnauldArnauld
84k799345
84k799345
add a comment |
add a comment |
$begingroup$
Ruby, 42 41+1 = 42 bytes
Add one byte for the p flag.
gsub(/w+/)$&.sub /(.)(.*)(.)/,'321'
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 42 41+1 = 42 bytes
Add one byte for the p flag.
gsub(/w+/)$&.sub /(.)(.*)(.)/,'321'
Try it online!
$endgroup$
add a comment |
$begingroup$
Ruby, 42 41+1 = 42 bytes
Add one byte for the p flag.
gsub(/w+/)$&.sub /(.)(.*)(.)/,'321'
Try it online!
$endgroup$
Ruby, 42 41+1 = 42 bytes
Add one byte for the p flag.
gsub(/w+/)$&.sub /(.)(.*)(.)/,'321'
Try it online!
answered 1 hour ago
Value InkValue Ink
8,075731
8,075731
add a comment |
add a comment |
$begingroup$
05AB1E, 10 bytes
#vyRćsRćðJ
Try it online!
-3 Thanks to The Kevster.
# | Split into words.
vy | For each word...
RćsRć | Reverse, split head, swap, reverse, split tail
ðJ | Join by spaces.
$endgroup$
1
$begingroup$
10 bytes
$endgroup$
– Kevin Cruijssen
1 hour ago
1
$begingroup$
@KevinCruijssen I honestly want to delete it and give it to you, that was 99% your brainpower on the ordering of the arguments haha.
$endgroup$
– Magic Octopus Urn
59 mins ago
$begingroup$
The 100% brainpower only took a minute, so you can have it. ;p My initial approach was a map like this:#εRćsRćJ}ðý. And then I noticed your loop and thought that just pushing a space char and joining the entire stack would save a trailing}, hence the 10 byter. I have the feeling a 9-byter might be possible, though..
$endgroup$
– Kevin Cruijssen
40 mins ago
$begingroup$
Found a 9-byter, but it only works in the legacy version:|ʒRćsRćJ,
$endgroup$
– Kevin Cruijssen
18 mins ago
$begingroup$
Too bad we don't have aloop_as_long_as_there_are_inputs, then I would have known an 8-byter:[RćsRćJ,This 8-byter using[never outputs in theory however, only when you're out of memory or time out like on TIO (and it requires a trailing newline in the input, otherwise it will keep using the last word)..
$endgroup$
– Kevin Cruijssen
13 mins ago
add a comment |
$begingroup$
05AB1E, 10 bytes
#vyRćsRćðJ
Try it online!
-3 Thanks to The Kevster.
# | Split into words.
vy | For each word...
RćsRć | Reverse, split head, swap, reverse, split tail
ðJ | Join by spaces.
$endgroup$
1
$begingroup$
10 bytes
$endgroup$
– Kevin Cruijssen
1 hour ago
1
$begingroup$
@KevinCruijssen I honestly want to delete it and give it to you, that was 99% your brainpower on the ordering of the arguments haha.
$endgroup$
– Magic Octopus Urn
59 mins ago
$begingroup$
The 100% brainpower only took a minute, so you can have it. ;p My initial approach was a map like this:#εRćsRćJ}ðý. And then I noticed your loop and thought that just pushing a space char and joining the entire stack would save a trailing}, hence the 10 byter. I have the feeling a 9-byter might be possible, though..
$endgroup$
– Kevin Cruijssen
40 mins ago
$begingroup$
Found a 9-byter, but it only works in the legacy version:|ʒRćsRćJ,
$endgroup$
– Kevin Cruijssen
18 mins ago
$begingroup$
Too bad we don't have aloop_as_long_as_there_are_inputs, then I would have known an 8-byter:[RćsRćJ,This 8-byter using[never outputs in theory however, only when you're out of memory or time out like on TIO (and it requires a trailing newline in the input, otherwise it will keep using the last word)..
$endgroup$
– Kevin Cruijssen
13 mins ago
add a comment |
$begingroup$
05AB1E, 10 bytes
#vyRćsRćðJ
Try it online!
-3 Thanks to The Kevster.
# | Split into words.
vy | For each word...
RćsRć | Reverse, split head, swap, reverse, split tail
ðJ | Join by spaces.
$endgroup$
05AB1E, 10 bytes
#vyRćsRćðJ
Try it online!
-3 Thanks to The Kevster.
# | Split into words.
vy | For each word...
RćsRć | Reverse, split head, swap, reverse, split tail
ðJ | Join by spaces.
edited 59 mins ago
answered 1 hour ago
Magic Octopus UrnMagic Octopus Urn
13.1k444126
13.1k444126
1
$begingroup$
10 bytes
$endgroup$
– Kevin Cruijssen
1 hour ago
1
$begingroup$
@KevinCruijssen I honestly want to delete it and give it to you, that was 99% your brainpower on the ordering of the arguments haha.
$endgroup$
– Magic Octopus Urn
59 mins ago
$begingroup$
The 100% brainpower only took a minute, so you can have it. ;p My initial approach was a map like this:#εRćsRćJ}ðý. And then I noticed your loop and thought that just pushing a space char and joining the entire stack would save a trailing}, hence the 10 byter. I have the feeling a 9-byter might be possible, though..
$endgroup$
– Kevin Cruijssen
40 mins ago
$begingroup$
Found a 9-byter, but it only works in the legacy version:|ʒRćsRćJ,
$endgroup$
– Kevin Cruijssen
18 mins ago
$begingroup$
Too bad we don't have aloop_as_long_as_there_are_inputs, then I would have known an 8-byter:[RćsRćJ,This 8-byter using[never outputs in theory however, only when you're out of memory or time out like on TIO (and it requires a trailing newline in the input, otherwise it will keep using the last word)..
$endgroup$
– Kevin Cruijssen
13 mins ago
add a comment |
1
$begingroup$
10 bytes
$endgroup$
– Kevin Cruijssen
1 hour ago
1
$begingroup$
@KevinCruijssen I honestly want to delete it and give it to you, that was 99% your brainpower on the ordering of the arguments haha.
$endgroup$
– Magic Octopus Urn
59 mins ago
$begingroup$
The 100% brainpower only took a minute, so you can have it. ;p My initial approach was a map like this:#εRćsRćJ}ðý. And then I noticed your loop and thought that just pushing a space char and joining the entire stack would save a trailing}, hence the 10 byter. I have the feeling a 9-byter might be possible, though..
$endgroup$
– Kevin Cruijssen
40 mins ago
$begingroup$
Found a 9-byter, but it only works in the legacy version:|ʒRćsRćJ,
$endgroup$
– Kevin Cruijssen
18 mins ago
$begingroup$
Too bad we don't have aloop_as_long_as_there_are_inputs, then I would have known an 8-byter:[RćsRćJ,This 8-byter using[never outputs in theory however, only when you're out of memory or time out like on TIO (and it requires a trailing newline in the input, otherwise it will keep using the last word)..
$endgroup$
– Kevin Cruijssen
13 mins ago
1
1
$begingroup$
10 bytes
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
10 bytes
$endgroup$
– Kevin Cruijssen
1 hour ago
1
1
$begingroup$
@KevinCruijssen I honestly want to delete it and give it to you, that was 99% your brainpower on the ordering of the arguments haha.
$endgroup$
– Magic Octopus Urn
59 mins ago
$begingroup$
@KevinCruijssen I honestly want to delete it and give it to you, that was 99% your brainpower on the ordering of the arguments haha.
$endgroup$
– Magic Octopus Urn
59 mins ago
$begingroup$
The 100% brainpower only took a minute, so you can have it. ;p My initial approach was a map like this:
#εRćsRćJ}ðý. And then I noticed your loop and thought that just pushing a space char and joining the entire stack would save a trailing }, hence the 10 byter. I have the feeling a 9-byter might be possible, though..$endgroup$
– Kevin Cruijssen
40 mins ago
$begingroup$
The 100% brainpower only took a minute, so you can have it. ;p My initial approach was a map like this:
#εRćsRćJ}ðý. And then I noticed your loop and thought that just pushing a space char and joining the entire stack would save a trailing }, hence the 10 byter. I have the feeling a 9-byter might be possible, though..$endgroup$
– Kevin Cruijssen
40 mins ago
$begingroup$
Found a 9-byter, but it only works in the legacy version:
|ʒRćsRćJ,$endgroup$
– Kevin Cruijssen
18 mins ago
$begingroup$
Found a 9-byter, but it only works in the legacy version:
|ʒRćsRćJ,$endgroup$
– Kevin Cruijssen
18 mins ago
$begingroup$
Too bad we don't have a
loop_as_long_as_there_are_inputs, then I would have known an 8-byter: [RćsRćJ, This 8-byter using [ never outputs in theory however, only when you're out of memory or time out like on TIO (and it requires a trailing newline in the input, otherwise it will keep using the last word)..$endgroup$
– Kevin Cruijssen
13 mins ago
$begingroup$
Too bad we don't have a
loop_as_long_as_there_are_inputs, then I would have known an 8-byter: [RćsRćJ, This 8-byter using [ never outputs in theory however, only when you're out of memory or time out like on TIO (and it requires a trailing newline in the input, otherwise it will keep using the last word)..$endgroup$
– Kevin Cruijssen
13 mins ago
add a comment |
$begingroup$
Python 3, 72 58 bytes
print(*[x[-1]+x[1:-1]+x[:x>x[0]]for x in input().split()])
Try it online!
$endgroup$
$begingroup$
Doesn't work for one letter words (ega)
$endgroup$
– TFeld
1 hour ago
$begingroup$
@TFeld, fixed..
$endgroup$
– alexz02
1 hour ago
add a comment |
$begingroup$
Python 3, 72 58 bytes
print(*[x[-1]+x[1:-1]+x[:x>x[0]]for x in input().split()])
Try it online!
$endgroup$
$begingroup$
Doesn't work for one letter words (ega)
$endgroup$
– TFeld
1 hour ago
$begingroup$
@TFeld, fixed..
$endgroup$
– alexz02
1 hour ago
add a comment |
$begingroup$
Python 3, 72 58 bytes
print(*[x[-1]+x[1:-1]+x[:x>x[0]]for x in input().split()])
Try it online!
$endgroup$
Python 3, 72 58 bytes
print(*[x[-1]+x[1:-1]+x[:x>x[0]]for x in input().split()])
Try it online!
edited 1 hour ago
answered 1 hour ago
alexz02alexz02
414
414
$begingroup$
Doesn't work for one letter words (ega)
$endgroup$
– TFeld
1 hour ago
$begingroup$
@TFeld, fixed..
$endgroup$
– alexz02
1 hour ago
add a comment |
$begingroup$
Doesn't work for one letter words (ega)
$endgroup$
– TFeld
1 hour ago
$begingroup$
@TFeld, fixed..
$endgroup$
– alexz02
1 hour ago
$begingroup$
Doesn't work for one letter words (eg
a)$endgroup$
– TFeld
1 hour ago
$begingroup$
Doesn't work for one letter words (eg
a)$endgroup$
– TFeld
1 hour ago
$begingroup$
@TFeld, fixed..
$endgroup$
– alexz02
1 hour ago
$begingroup$
@TFeld, fixed..
$endgroup$
– alexz02
1 hour ago
add a comment |
$begingroup$
Retina, 8 5 bytes
,V,,`
Try it online!
Saved 3 bytes thanks to Kevin Cruijssen!
Uses a newline as the separator. We make use of Retina's reverse stage and some limits. The first limit is which matches to apply the reversal to, so we pick all of them with ,. Then we want the first and last letter of each match to be swapped, so we take each letter in the range ,, which translates to a range from the beginning to the end with step size zero.
$endgroup$
$begingroup$
Dangit, I was just searching through the docs for something like this to update my answer, but you beat me to it. I knew aboutV, but didn't knew it could be used with the indices1,-2like that. Nice one!
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@KevinCruijssen I cheated a little and reviewed how limit ranges worked while this was in the sandbox :) I still feel like there should be a better way than inverting a range but I haven't been able to find anything shorter.
$endgroup$
– FryAmTheEggman
1 hour ago
1
$begingroup$
You're indeed right that it can be shorter without a limit-range, because it seems this 5-byter works (given as example at the bottom of the Step Limits in the docs).
$endgroup$
– Kevin Cruijssen
47 mins ago
$begingroup$
@KevinCruijssen Nice! Can't believe I missed that.
$endgroup$
– FryAmTheEggman
37 mins ago
add a comment |
$begingroup$
Retina, 8 5 bytes
,V,,`
Try it online!
Saved 3 bytes thanks to Kevin Cruijssen!
Uses a newline as the separator. We make use of Retina's reverse stage and some limits. The first limit is which matches to apply the reversal to, so we pick all of them with ,. Then we want the first and last letter of each match to be swapped, so we take each letter in the range ,, which translates to a range from the beginning to the end with step size zero.
$endgroup$
$begingroup$
Dangit, I was just searching through the docs for something like this to update my answer, but you beat me to it. I knew aboutV, but didn't knew it could be used with the indices1,-2like that. Nice one!
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@KevinCruijssen I cheated a little and reviewed how limit ranges worked while this was in the sandbox :) I still feel like there should be a better way than inverting a range but I haven't been able to find anything shorter.
$endgroup$
– FryAmTheEggman
1 hour ago
1
$begingroup$
You're indeed right that it can be shorter without a limit-range, because it seems this 5-byter works (given as example at the bottom of the Step Limits in the docs).
$endgroup$
– Kevin Cruijssen
47 mins ago
$begingroup$
@KevinCruijssen Nice! Can't believe I missed that.
$endgroup$
– FryAmTheEggman
37 mins ago
add a comment |
$begingroup$
Retina, 8 5 bytes
,V,,`
Try it online!
Saved 3 bytes thanks to Kevin Cruijssen!
Uses a newline as the separator. We make use of Retina's reverse stage and some limits. The first limit is which matches to apply the reversal to, so we pick all of them with ,. Then we want the first and last letter of each match to be swapped, so we take each letter in the range ,, which translates to a range from the beginning to the end with step size zero.
$endgroup$
Retina, 8 5 bytes
,V,,`
Try it online!
Saved 3 bytes thanks to Kevin Cruijssen!
Uses a newline as the separator. We make use of Retina's reverse stage and some limits. The first limit is which matches to apply the reversal to, so we pick all of them with ,. Then we want the first and last letter of each match to be swapped, so we take each letter in the range ,, which translates to a range from the beginning to the end with step size zero.
edited 39 mins ago
answered 1 hour ago
FryAmTheEggmanFryAmTheEggman
14.8k32583
14.8k32583
$begingroup$
Dangit, I was just searching through the docs for something like this to update my answer, but you beat me to it. I knew aboutV, but didn't knew it could be used with the indices1,-2like that. Nice one!
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@KevinCruijssen I cheated a little and reviewed how limit ranges worked while this was in the sandbox :) I still feel like there should be a better way than inverting a range but I haven't been able to find anything shorter.
$endgroup$
– FryAmTheEggman
1 hour ago
1
$begingroup$
You're indeed right that it can be shorter without a limit-range, because it seems this 5-byter works (given as example at the bottom of the Step Limits in the docs).
$endgroup$
– Kevin Cruijssen
47 mins ago
$begingroup$
@KevinCruijssen Nice! Can't believe I missed that.
$endgroup$
– FryAmTheEggman
37 mins ago
add a comment |
$begingroup$
Dangit, I was just searching through the docs for something like this to update my answer, but you beat me to it. I knew aboutV, but didn't knew it could be used with the indices1,-2like that. Nice one!
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@KevinCruijssen I cheated a little and reviewed how limit ranges worked while this was in the sandbox :) I still feel like there should be a better way than inverting a range but I haven't been able to find anything shorter.
$endgroup$
– FryAmTheEggman
1 hour ago
1
$begingroup$
You're indeed right that it can be shorter without a limit-range, because it seems this 5-byter works (given as example at the bottom of the Step Limits in the docs).
$endgroup$
– Kevin Cruijssen
47 mins ago
$begingroup$
@KevinCruijssen Nice! Can't believe I missed that.
$endgroup$
– FryAmTheEggman
37 mins ago
$begingroup$
Dangit, I was just searching through the docs for something like this to update my answer, but you beat me to it. I knew about
V, but didn't knew it could be used with the indices 1,-2 like that. Nice one!$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
Dangit, I was just searching through the docs for something like this to update my answer, but you beat me to it. I knew about
V, but didn't knew it could be used with the indices 1,-2 like that. Nice one!$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@KevinCruijssen I cheated a little and reviewed how limit ranges worked while this was in the sandbox :) I still feel like there should be a better way than inverting a range but I haven't been able to find anything shorter.
$endgroup$
– FryAmTheEggman
1 hour ago
$begingroup$
@KevinCruijssen I cheated a little and reviewed how limit ranges worked while this was in the sandbox :) I still feel like there should be a better way than inverting a range but I haven't been able to find anything shorter.
$endgroup$
– FryAmTheEggman
1 hour ago
1
1
$begingroup$
You're indeed right that it can be shorter without a limit-range, because it seems this 5-byter works (given as example at the bottom of the Step Limits in the docs).
$endgroup$
– Kevin Cruijssen
47 mins ago
$begingroup$
You're indeed right that it can be shorter without a limit-range, because it seems this 5-byter works (given as example at the bottom of the Step Limits in the docs).
$endgroup$
– Kevin Cruijssen
47 mins ago
$begingroup$
@KevinCruijssen Nice! Can't believe I missed that.
$endgroup$
– FryAmTheEggman
37 mins ago
$begingroup$
@KevinCruijssen Nice! Can't believe I missed that.
$endgroup$
– FryAmTheEggman
37 mins ago
add a comment |
$begingroup$
QuadR, 20 bytes
(w)(w*)(w)
321
Simply make three capturing groups consisting of 1, 0-or-more, and 1 word-characters, then reverses their order.
Try it online!
$endgroup$
add a comment |
$begingroup$
QuadR, 20 bytes
(w)(w*)(w)
321
Simply make three capturing groups consisting of 1, 0-or-more, and 1 word-characters, then reverses their order.
Try it online!
$endgroup$
add a comment |
$begingroup$
QuadR, 20 bytes
(w)(w*)(w)
321
Simply make three capturing groups consisting of 1, 0-or-more, and 1 word-characters, then reverses their order.
Try it online!
$endgroup$
QuadR, 20 bytes
(w)(w*)(w)
321
Simply make three capturing groups consisting of 1, 0-or-more, and 1 word-characters, then reverses their order.
Try it online!
answered 1 hour ago
AdámAdám
27.7k276207
27.7k276207
add a comment |
add a comment |
$begingroup$
Stax, 11 bytes
ô"┼▼φƒY╛»u~
Run and debug it
$endgroup$
add a comment |
$begingroup$
Stax, 11 bytes
ô"┼▼φƒY╛»u~
Run and debug it
$endgroup$
add a comment |
$begingroup$
Stax, 11 bytes
ô"┼▼φƒY╛»u~
Run and debug it
$endgroup$
Stax, 11 bytes
ô"┼▼φƒY╛»u~
Run and debug it
edited 1 hour ago
answered 1 hour ago
recursiverecursive
5,8241322
5,8241322
add a comment |
add a comment |
$begingroup$
Python 2, 67 66 64 61 bytes
lambda s:' '.join(w[-1]+w[1:-1]+w[:w>w[0]]for w in s.split())
Try it online!
-1 byte, thanks to squid
Python 3, 63 61 58 bytes
print(*[w[-1]+w[1:-1]+w[:w>w[0]]for w in input().split()])
Try it online!
$endgroup$
$begingroup$
You can remove the whitespace before ">"
$endgroup$
– squid
1 hour ago
$begingroup$
@squid thanks. I'm on mobile, so whitespace is hard on tio.
$endgroup$
– TFeld
1 hour ago
$begingroup$
Your 58-byte version is now an exact (except for the variable name) copy of alexz02's latest edit from 20 minutes ago
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@kevincruijssen ergh.. To be fair, that answer is a trivial golf of my earlier edit...
$endgroup$
– TFeld
59 mins ago
2
$begingroup$
True. I was mentioning it merely as a FYI. :) There isn't any rule disqualifying duplicated answers when both users independently came to the same solutions.
$endgroup$
– Kevin Cruijssen
56 mins ago
add a comment |
$begingroup$
Python 2, 67 66 64 61 bytes
lambda s:' '.join(w[-1]+w[1:-1]+w[:w>w[0]]for w in s.split())
Try it online!
-1 byte, thanks to squid
Python 3, 63 61 58 bytes
print(*[w[-1]+w[1:-1]+w[:w>w[0]]for w in input().split()])
Try it online!
$endgroup$
$begingroup$
You can remove the whitespace before ">"
$endgroup$
– squid
1 hour ago
$begingroup$
@squid thanks. I'm on mobile, so whitespace is hard on tio.
$endgroup$
– TFeld
1 hour ago
$begingroup$
Your 58-byte version is now an exact (except for the variable name) copy of alexz02's latest edit from 20 minutes ago
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@kevincruijssen ergh.. To be fair, that answer is a trivial golf of my earlier edit...
$endgroup$
– TFeld
59 mins ago
2
$begingroup$
True. I was mentioning it merely as a FYI. :) There isn't any rule disqualifying duplicated answers when both users independently came to the same solutions.
$endgroup$
– Kevin Cruijssen
56 mins ago
add a comment |
$begingroup$
Python 2, 67 66 64 61 bytes
lambda s:' '.join(w[-1]+w[1:-1]+w[:w>w[0]]for w in s.split())
Try it online!
-1 byte, thanks to squid
Python 3, 63 61 58 bytes
print(*[w[-1]+w[1:-1]+w[:w>w[0]]for w in input().split()])
Try it online!
$endgroup$
Python 2, 67 66 64 61 bytes
lambda s:' '.join(w[-1]+w[1:-1]+w[:w>w[0]]for w in s.split())
Try it online!
-1 byte, thanks to squid
Python 3, 63 61 58 bytes
print(*[w[-1]+w[1:-1]+w[:w>w[0]]for w in input().split()])
Try it online!
edited 1 hour ago
answered 1 hour ago
TFeldTFeld
16.8k31451
16.8k31451
$begingroup$
You can remove the whitespace before ">"
$endgroup$
– squid
1 hour ago
$begingroup$
@squid thanks. I'm on mobile, so whitespace is hard on tio.
$endgroup$
– TFeld
1 hour ago
$begingroup$
Your 58-byte version is now an exact (except for the variable name) copy of alexz02's latest edit from 20 minutes ago
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@kevincruijssen ergh.. To be fair, that answer is a trivial golf of my earlier edit...
$endgroup$
– TFeld
59 mins ago
2
$begingroup$
True. I was mentioning it merely as a FYI. :) There isn't any rule disqualifying duplicated answers when both users independently came to the same solutions.
$endgroup$
– Kevin Cruijssen
56 mins ago
add a comment |
$begingroup$
You can remove the whitespace before ">"
$endgroup$
– squid
1 hour ago
$begingroup$
@squid thanks. I'm on mobile, so whitespace is hard on tio.
$endgroup$
– TFeld
1 hour ago
$begingroup$
Your 58-byte version is now an exact (except for the variable name) copy of alexz02's latest edit from 20 minutes ago
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@kevincruijssen ergh.. To be fair, that answer is a trivial golf of my earlier edit...
$endgroup$
– TFeld
59 mins ago
2
$begingroup$
True. I was mentioning it merely as a FYI. :) There isn't any rule disqualifying duplicated answers when both users independently came to the same solutions.
$endgroup$
– Kevin Cruijssen
56 mins ago
$begingroup$
You can remove the whitespace before ">"
$endgroup$
– squid
1 hour ago
$begingroup$
You can remove the whitespace before ">"
$endgroup$
– squid
1 hour ago
$begingroup$
@squid thanks. I'm on mobile, so whitespace is hard on tio.
$endgroup$
– TFeld
1 hour ago
$begingroup$
@squid thanks. I'm on mobile, so whitespace is hard on tio.
$endgroup$
– TFeld
1 hour ago
$begingroup$
Your 58-byte version is now an exact (except for the variable name) copy of alexz02's latest edit from 20 minutes ago
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
Your 58-byte version is now an exact (except for the variable name) copy of alexz02's latest edit from 20 minutes ago
$endgroup$
– Kevin Cruijssen
1 hour ago
$begingroup$
@kevincruijssen ergh.. To be fair, that answer is a trivial golf of my earlier edit...
$endgroup$
– TFeld
59 mins ago
$begingroup$
@kevincruijssen ergh.. To be fair, that answer is a trivial golf of my earlier edit...
$endgroup$
– TFeld
59 mins ago
2
2
$begingroup$
True. I was mentioning it merely as a FYI. :) There isn't any rule disqualifying duplicated answers when both users independently came to the same solutions.
$endgroup$
– Kevin Cruijssen
56 mins ago
$begingroup$
True. I was mentioning it merely as a FYI. :) There isn't any rule disqualifying duplicated answers when both users independently came to the same solutions.
$endgroup$
– Kevin Cruijssen
56 mins ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 92 bytes
StringRiffle[StringReplacePart[#,StringTake[#,1,-1],-1,-1,1,1]&/@StringSplit@#]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 92 bytes
StringRiffle[StringReplacePart[#,StringTake[#,1,-1],-1,-1,1,1]&/@StringSplit@#]&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 92 bytes
StringRiffle[StringReplacePart[#,StringTake[#,1,-1],-1,-1,1,1]&/@StringSplit@#]&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 92 bytes
StringRiffle[StringReplacePart[#,StringTake[#,1,-1],-1,-1,1,1]&/@StringSplit@#]&
Try it online!
answered 1 hour ago
J42161217J42161217
15k21457
15k21457
add a comment |
add a comment |
$begingroup$
Perl 5 -p, 24 bytes
s/(w)(w*)(w)/$3$2$1/g
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -p, 24 bytes
s/(w)(w*)(w)/$3$2$1/g
Try it online!
$endgroup$
add a comment |
$begingroup$
Perl 5 -p, 24 bytes
s/(w)(w*)(w)/$3$2$1/g
Try it online!
$endgroup$
Perl 5 -p, 24 bytes
s/(w)(w*)(w)/$3$2$1/g
Try it online!
answered 59 mins ago
XcaliXcali
5,760522
5,760522
add a comment |
add a comment |
$begingroup$
PHP, 73 bytes
foreach(explode(' ',$argn)as$w)[$w[0],$w[-1]]=[$w[-1],$w[0]];echo"$w ";
Try it online!
Using PHP 7.1's Square bracket syntax for array destructuring.
$endgroup$
add a comment |
$begingroup$
PHP, 73 bytes
foreach(explode(' ',$argn)as$w)[$w[0],$w[-1]]=[$w[-1],$w[0]];echo"$w ";
Try it online!
Using PHP 7.1's Square bracket syntax for array destructuring.
$endgroup$
add a comment |
$begingroup$
PHP, 73 bytes
foreach(explode(' ',$argn)as$w)[$w[0],$w[-1]]=[$w[-1],$w[0]];echo"$w ";
Try it online!
Using PHP 7.1's Square bracket syntax for array destructuring.
$endgroup$
PHP, 73 bytes
foreach(explode(' ',$argn)as$w)[$w[0],$w[-1]]=[$w[-1],$w[0]];echo"$w ";
Try it online!
Using PHP 7.1's Square bracket syntax for array destructuring.
answered 9 mins ago
gwaughgwaugh
2,7681720
2,7681720
add a comment |
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%2f185674%2fpwas-eht-tirsf-dna-tasl-setterl-fo-hace-dorw%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$
How should punctuation be treated?
Hello, world!becomes,elloH !orldw(swapping punctuation as a letter) oroellH, dorlw!(keeping punctuation in place)?$endgroup$
– Phelype Oleinik
2 hours ago
$begingroup$
@PhelypeOleinik You do not need to handle punctuation; all of the inputs will only consist of the letters a through z, and all a uniform case.
$endgroup$
– Comrade SparklePony
2 hours ago
2
$begingroup$
Second paragraph reads as well as one other character to use as a delimiter while the fourth reads separated by spaces. Which one is it?
$endgroup$
– Adám
1 hour ago