| Bytes | Lang | Time | Link |
|---|---|---|---|
| 019 | Perl 5 a | 241107T211847Z | Xcali |
| 008 | Uiua | 241107T205400Z | nyxbird |
| 022 | AWK | 241107T200421Z | xrs |
| 013 | Zsh | 230709T101125Z | roblogic |
| 002 | Thunno 2 Ṡ | 230709T090331Z | The Thon |
| 005 | MATL | 170518T001935Z | Suever |
| 003 | Vyxal | 210628T025148Z | Wasif |
| 034 | GNU sed 4.2.2 | 210627T014958Z | Marco |
| 029 | PowerShell Core | 210624T024532Z | Julian |
| 040 | Wren | 191218T142205Z | user8505 |
| 011 | tcl | 170628T165847Z | sergiol |
| 018 | tcl | 170628T152315Z | sergiol |
| 004 | Japt | 170518T071516Z | Shaggy |
| 003 | Pyth | 170528T235117Z | AAM111 |
| 025 | Röda | 170517T194328Z | user4180 |
| 028 | AWK | 170517T155358Z | Robert B |
| 020 | Vim | 170523T161946Z | DJMcMayh |
| 042 | Vim | 170518T102310Z | Hex |
| 035 | Mathematica | 170518T003116Z | ZaMoC |
| 023 | Juby | 170519T213422Z | Cyoce |
| 042 | Lua | 170517T223229Z | Felipe N |
| 053 | Java 8 | 170518T132910Z | user9023 |
| 048 | C | 170518T113756Z | Khaled.K |
| 057 | Clojurescript | 170519T023743Z | madstap |
| nan | 170519T001257Z | Brad Gil | |
| 116 | Swift | 170518T153002Z | Caleb Kl |
| 024 | Ruby | 170518T104344Z | marmelad |
| 062 | Java 8 | 170518T081726Z | Kevin Cr |
| 027 | jq | 170518T090723Z | manatwor |
| 029 | Gema | 170518T090359Z | manatwor |
| 037 | Scala | 170518T082850Z | Kevin Cr |
| 026 | Cheddar | 170517T152252Z | Leaky Nu |
| 048 | Cubix | 170518T030639Z | MickyT |
| 074 | brainfuck | 170518T014915Z | Nitrodon |
| 017 | Stacked | 170518T001317Z | Conor O& |
| 006 | J | 170518T001022Z | Conor O& |
| 009 | k | 170518T000943Z | zgrep |
| nan | Ruby | 170517T225141Z | Value In |
| 006 | Brachylog | 170517T161536Z | Fatalize |
| 021 | Bash + common Linux utilities | 170517T161517Z | Digital |
| 058 | C# | 170517T155157Z | TheLetha |
| 007 | TAESGL | 170517T150825Z | Tom |
| 019 | R | 170517T153203Z | Giuseppe |
| 029 | Python 3 | 170517T153004Z | Rod |
| 062 | GNU Make | 170517T152648Z | eush77 |
| 047 | PHP | 170517T152253Z | Jör |
| 007 | CJam | 170517T150838Z | Business |
| 004 | Ohm | 170517T151654Z | Business |
| 021 | Haskell | 170517T150828Z | nimi |
| 004 | 05AB1E | 170517T150543Z | Okx |
| 004 | Pyth | 170517T150432Z | notjagan |
| 003 | Jelly | 170517T150327Z | steenber |
| 031 | JavaScript ES6 | 170517T150322Z | Shaggy |
| 007 | Retina | 170517T150255Z | Martin E |
| 034 | Python 2 | 170517T150219Z | totallyh |
Uiua, 8 bytes
⍜⊜□⇌⊸≠@
Note the trailing space.
⍜ under ⊜ partitioning into □ boxes ⊸ by ≠ inequality to @ space, ⇌ reverse.
AWK, -vRS=" " 22 bytes
{s=$1" "s}END{print s}
To test:
awk -vRS=" " '{s=$1" "s}END{print s}' <<< "The quick brown fox jumps over the lazy dog"
Thunno 2 Ṡ, 2 bytes
Or
Explanation
# Implicit input
O # Split on spaces
r # Reverse
# Join on spaces
# Implicit output
MATL, 5 bytes
YbPZc
Try it at MATL Online!
Explanation
% Implicitly grab input as a string
Yb % Split it on all of the spaces, yielding a cell array of words
P % Flip this array
Zc % Join these words back together with spaces
% Implicitly display the result
GNU sed 4.2.2, 34 bytes
Score includes +1 for -r passed to GNU sed.
:
s/(\w*) ([^:]*)/\2:\1/
t
y/:/ /
Another answer, 38 bytes:
s/^/:/
:
s/:(.*) (.*)/\2 :\1/
t
s/://
Wren, 40 bytes
Fn.new{|a|a.split(" ")[-1..0].join(" ")}
Explanation
Fn.new{|a| } // Anonymous function with the parameter a
a.split(" ") // Split on spaces
[-1..0] // Reverse the array
.join(" ") // Join the array with spaces
tcl, 11
lreverse ""
^
|
Put the string you want to test here between the ""
Can be tested on http://www.tutorialspoint.com/execute_tcl_online.php starting the tcl interpreter by typing tclsh. Then type
lreverse "Man bites dog"
%
lreverse "The quick brown fox jumps over the lazy dog"
%
lreverse "Hello world"
Japt, 11 10 7 4 bytes
My first attempt at Japt.
¸w ¸
- Saved 3 bytes thanks to ETHproductions
Explanation
:Implicit input of string U
¸ :Split on <space>
w :Reverse
¸ :Join with <space>
Please share your Japt tips here.
Pyth, 3 bytes
_cw
My first Pyth answer, one byte shorter than @notjagan's answer!
Explained:
cw # Split the input by space (same as Python's string.split())
_ # Reverses the array
# Pyth prints implicitly.
Röda, 27 25 bytes
2 bytes saved thanks to @fergusq
{[[split()|reverse]&" "]}
This function takes input from the input stream.
Explanation (outdated)
{[[(_/" ")()|reverse]&" "]} /* Anonymous function */
(_/" ") /* Pull a value from the stream and split it on spaces */
() /* Push all the values in the resulting array to the stream */
|reverse /* And reverse it */
[ ] /* Wrap the result into an array*/
&" " /* Concatenate each of the strings in the array with a space */
[ ] /* And push this result to the output stream */
Vim, 49 42 bytes
:s/.*/\=join(reverse(split(submatch(0))))/
Thank you to @manatwork for feedback
J-uby, 23 bytes
:split|:reverse|~:*&' '
Explanation
:split # split by spaces
| # then
:reverse # reverse
| # then
~:*&' ' # join with spaces
Java 8, 53 57 bytes
Lambda + Stream API
s->Stream.of(s.split(" ")).reduce("",(a,b)->b+" "+a)
Following Selim suggestion, we just dropped 4 bytes
C, 54 48 bytes
Using arguments as input, 48 bytes
main(c,v)char**v;{while(--c)printf("%s ",v[c]);}
> ./a.out man bites dog
Using pointers, 84 bytes
f(char*s){char*t=s;while(*t)t++;while(t-s){while(*t>32)t--;*t=0;printf("%s ",t+1);}}
Use
main(){ f("man bites dog"); }
Clojure(script), 57 bytes
#(apply str(interpose" "(reverse(re-seq #"[a-zA-Z]+"%))))
Perl 6, 14 bytes
{~[R,] .words}
Expanded:
{ # lambda with implicit param $_
~ # stringify following (joins a list using spaces)
[R,] # reduce the following using the Reverse meta operator
.words # call the words method on $_
}
Swift, 116 bytes
var r:(String)->String={return $0.characters.split(separator:" ").map(String.init).reversed().joined(separator:" ")}
You can try it here
Ruby, 27 24 bytes
thanks to @manatwork
->a{a.split.reverse*" "}
Java 8, 62 bytes
s->{String r="";for(String x:s.split(" "))r=x+" "+r;return r;}
Java 7, 77 bytes
String c(String s){String r="";for(String x:s.split(" "))r=x+" "+r;return r;}
jq, 27 characters
(23 characters code + 4 characters command line options)
./" "|reverse|join(" ")
Sample run:
bash-4.4$ jq -Rr './" "|reverse|join(" ")' <<< 'Man bites dog'
dog bites Man
Gema, 29 characters
<W><s>=@set{o;$1 ${o;}}
\Z=$o
Sample run:
bash-4.4$ gema '<W><s>=@set{o;$1 ${o;}};\Z=$o' <<< 'Man bites dog'
dog bites Man
Cubix, 48 bytes
Almost gave up on this one, but finally got there.
oU_;SW;@?ABu>):tS-?;\0$q^s.$;;<$|1osU!(;;...<#(1
This maps onto a cube with a side length of three as follows
o U _
; S W
; @ ?
A B u > ) : t S - ? ; \
0 $ q ^ s . $ ; ; < $ |
1 o s U ! ( ; ; . . . <
# ( 1
. . .
. . .
The general steps are:
- Get all input
Aand reverseBstack - Move the negative
qto the bottom, add a counter0to the stack. bit of jumping around in here. - Find space/end loop, also puts stack in correct print order.
- Increment counter
)and fetch the counter item from the stackt - Is it a space or EOI
S-? - Repeat if not
- Increment counter
- Print word loop
- Decrement counter
( - Exit loop if counter
!Uis 0 - Swap
scounter with character on stack - Print
ocharacter and pop it from the stack; - Repeat loop
- Decrement counter
- Get the length of the stack
#and decrement( - Check
?if 0 and exit@if it is 0 - Otherwise print a space
Soclean up;;and go back to the first loop.
I've skipped a number of superfluous steps, but you can see it Step By Step
brainfuck, 74 bytes
,[>++++[<-------->-],]<[>++++[->--------<]+>[[<]>[+>]<]<-[<]>[.>]<[[-]<]<]
This code creates the number -32 in two different places, but that seems to be fewer bytes than trying to maintain a single -32.
Explanation
,[ input first character
>++++[<-------->-] subtract 32 from current character (so space becomes zero)
,] repeat for all characters in input
< go to last character of last word
[ while there are more words to display:
>++++[->--------<] create -32 two cells right of last letter
+> increment trailing space cell (1 right of last letter) so the next loop works
[[<]>[+>]<] add 32 to all cells in word and trailing space cell
<- subtract the previously added 1 from the trailing space
[<]> move pointer to beginning of word
[.>]< output word (with trailing space)
[[-]<] erase word
< move to last character of previous word
]
J, 6 bytes
|.&.;:
Try it online! This is reverse (|.) under (&.) words (;:). That is, split sentence into words, reverse it, and join the sentence again.
k, 9 bytes
" "/|" "\
Try it in your browser of the web variety!
" "\ /split on spaces
| /reverse
" "/ /join with spaces
Brachylog, 6 bytes
ṇ₁↔~ṇ₁
Explanation
ṇ₁ Split on spaces
↔ Reverse
~ṇ₁ Join with spaces
Note that both "split on spaces" and "join wth spaces" use the same built-in, that is ṇ₁, just used in different "directions".
Bash + common Linux utilities, 21
printf "$1 "|tac -s\
Leaves a trailing space in the output string - not sure if that's OK or not.
C#, 58 bytes
using System.Linq;s=>string.Join(" ",s.Split().Reverse());
TAESGL, 7 bytes
ĴS)Ř)ĴS
Explanation
ĴS)Ř)ĴS
AĴS) implicit input "A" split at " "
Ř) reversed
ĴS joined with " "
R, 19 bytes
cat(rev(scan(,'')))
reads the string from stdin. By default, scan reads tokens separated by spaces/newlines, so it reads the words in as a vector. rev reverses, and cat prints the elements with spaces.
GNU Make, 62 bytes
$(if $1,$(call $0,$(wordlist 2,$(words $1),$1)) $(word 1,$1),)
CJam, 7 bytes
qS/W%S*
Explanation
q e# Read input
S/ e# Split on spaces
W% e# Reverse
S* e# Join with spaces
Ohm, 4 bytes
z]Qù
Explanation
z Split the input on spaces.
] Dump it onto the stack.
Q Reverse the stack.
ù Join the stack with spaces. Implicit output.
Jelly, 3 bytes
ḲṚK
Explanation:
Ḳ Splits the input at spaces
Ṛ Reverses the array
K Joins the array, using spaces
JavaScript (ES6), 31 bytes
s=>s.split` `.reverse().join` `
Try it
f=
s=>s.split` `.reverse().join` `
o.innerText=f(i.value="Man bites dog")
oninput=_=>o.innerText=f(i.value)
<input id=i><pre id=o>
Retina, 7 bytes
O$^`\w+
Match all words (\w+) sort them with sort key empty string (O$) which means they won't get sorted at all, and then reverse their order (^).