Reverse words in a string: Difference between revisions
Added Easylang
(→{{header|Kotlin}}: Filter out empty tokens, which strips leading/trailing spaces, and compresses multiple spaces) |
(Added Easylang) |
||
(30 intermediate revisions by 26 users not shown) | |||
Line 41:
* [[Phrase reversals]]
<br><br>
=={{header|11l}}==
{{trans|Python}}
<syntaxhighlight lang="11l">V text =
‘---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------’
L(line) text.split("\n")
print(reversed(line.split(‘ ’)).join(‘ ’))</syntaxhighlight>
{{out}}
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
... last paragraph elided ...
----------------------- Robert Frost
</pre>
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Reverse(CHAR ARRAY src,dst)
BYTE i,j,k,beg,end
i=1 j=src(0)
WHILE j>0
DO
WHILE j>0 AND src(j)=$20
DO j==-1 OD
IF j=0 THEN
EXIT
ELSE
end=j
FI
WHILE j>0 AND src(j)#$20
DO j==-1 OD
beg=j+1
IF i>1 THEN
dst(i)=$20 i==+1
FI
FOR k=beg TO end
DO
dst(i)=src(k) i==+1
OD
OD
dst(0)=i-1
RETURN
PROC Test(CHAR ARRAY src)
CHAR ARRAY dst(40)
Reverse(src,dst)
PrintE(dst)
RETURN
PROC Main()
Test("---------- Ice and Fire ------------")
Test("")
Test("fire, in end will world the say Some")
Test("ice. in say Some")
Test("desire of tasted I've what From")
Test("fire. favor who those with hold I")
Test("")
Test("... elided paragraph last ...")
Test("")
Test("Frost Robert -----------------------")
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Reverse_words_in_a_string.png Screenshot from Atari 8-bit computer]
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
... last paragraph elided ...
----------------------- Robert Frost
</pre>
=={{header|Ada}}==
Line 48 ⟶ 145:
To Split a string into words, we define a Package "Simple_Parse". This package is also used for the Phrase Reversal Task [[http://rosettacode.org/wiki/Phrase_reversals#Ada]].
<
-- a very simplistic parser, useful to split a string into words
Line 58 ⟶ 155:
-- else Next_Word sets Point to S'Last+1 and returns ""
end Simple_Parse;</
The implementation of "Simple_Parse":
<
function Next_Word(S: String; Point: in out Positive) return String is
Line 81 ⟶ 178:
end Next_Word;
end Simple_Parse;</
===Main Program===
<
procedure Reverse_Words is
Line 105 ⟶ 202:
Put_Line(Reverse_Words(Get_Line)); -- poem is read from standard input
end loop;
end Reverse_Words;</
=={{header|Aime}}==
<
list l, x;
text s, t;
Line 130 ⟶ 227:
}
o_newline();
}</
{{out}}
<pre>------------ Fire and Ice ----------
Line 144 ⟶ 241:
=={{header|ALGOL 68}}==
<
# a word is a sequence of non-blank characters #
PROC reverse word order = ( STRING original phrase )STRING:
Line 187 ⟶ 284:
print( ( reverse word order ( " " ), newline ) );
print( ( reverse word order ( "Frost Robert -----------------------" ), newline ) )
</syntaxhighlight>
{{out}}
<pre>
Line 204 ⟶ 301:
=={{header|AppleScript}}==
<
unlines(map(reverseWords, |lines|("---------- Ice and Fire ------------
Line 295 ⟶ 392:
end if
end mReturn
</syntaxhighlight>
{{out}}
Line 310 ⟶ 407:
=={{header|Applesoft BASIC}}==
<
110 DATA" "
120 DATA"FIRE, IN END WILL WORLD THE SAY SOME"
Line 336 ⟶ 433:
350 IF C$ <> " " THEN W$ = C$ + W$ : NEXT I
360 RETURN
</syntaxhighlight>
=={{header|Arturo}}==
<
---------- Ice and Fire ------------
Line 354 ⟶ 451:
[join.with:" " reverse split.words &]
print join.with:"\n" reversed</
{{out}}
Line 370 ⟶ 467:
=={{header|AutoHotkey}}==
<
(Join`r`n
---------- Ice and Fire ------------
Line 390 ⟶ 487:
Output .= Line "`n", Line := ""
}
MsgBox, % RTrim(Output, "`n")</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f REVERSE_WORDS_IN_A_STRING.AWK
BEGIN {
Line 416 ⟶ 513:
exit(0)
}
</syntaxhighlight>
{{Output}}
<pre>
Line 432 ⟶ 529:
=={{header|BaCon}}==
<
PRINT REV$("---------- Ice and Fire ------------")
PRINT
Line 443 ⟶ 540:
PRINT
PRINT REV$("Frost Robert -----------------------")
</syntaxhighlight>
Using the REV$ function which takes a sentence as a delimited string where the items are separated by a delimiter (the space character is the default delimiter).
{{out}}
Line 460 ⟶ 557:
=={{header|Batch File}}==
<
::The Main Thing...
Line 494 ⟶ 591:
echo.%reversed%
goto :EOF
::/The Function...</
{{Out}}
<pre>
Line 509 ⟶ 606:
</pre>
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic256">source = freefile
open (source, "m:\text.txt")
textEnt$ = ""
dim textSal$(size(source)*8)
linea = 0
while not eof(source)
textEnt$ = readline(source)
linea += 1
textSal$[linea] = textEnt$
end while
for n = size(source) to 1 step -1
print textSal$[n];
next n
close source</syntaxhighlight>
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
\ 'FNreverse("")\
\ 'FNreverse("fire, in end will world the say Some")\
Line 527 ⟶ 643:
LOCAL sp%
sp%=INSTR(s$," ")
IF sp% THEN =FNreverse(MID$(s$,sp%+1))+" "+LEFT$(s$,sp%-1) ELSE =s$</
{{out}}
Line 540 ⟶ 656:
----------------------- Robert Frost</pre>
=={{header|BQN}}==
<syntaxhighlight lang="bqn">Split ← +`∘<⟜»⊸×⊸-⟜¬∘>⟜' '⊸⊔
Join ← (⊣∾' '∾⊢)´⍟(1<≡)
text ← ⍉≍⟨
"---------- Ice and Fire ------------"
""
"fire, in end will world the say Some"
"ice. in say Some "
"desire of tasted I've what From "
"fire. favor who those with hold I "
""
"... elided paragraph last ..."
""
"Frost Robert -----------------------"⟩
Join∘⌽∘Split¨ text</syntaxhighlight>
Alternative based on the approach described in [https://saltysylvi.github.io/blog/flat1.html this blog post]:
<syntaxhighlight lang="bqn">{(⍒+`∨⟜»' '=𝕩)⊏𝕩}¨ text</syntaxhighlight>
{{out}}
<pre>┌─
╵ "------------ Fire and Ice ----------"
⟨⟩
"Some say the world will end in fire,"
"Some say in ice."
"From what I've tasted of desire"
"I hold with those who favor fire."
⟨⟩
"... last paragraph elided ..."
⟨⟩
"----------------------- Robert Frost"
┘</pre>
=={{header|Bracmat}}==
<
fire, in end will world the say Some
Line 578 ⟶ 727:
& !output reverse$!text:?output
& out$str$!output
);</
{{out}}
<pre>------------ Fire and Ice ----------
Line 592 ⟶ 741:
=={{header|Burlesque}}==
<
blsq ) "It is not raining"wd<-wd
"raining not is It"
blsq ) "ice. in say some"wd<-wd
"some say in ice."
</syntaxhighlight>
=={{header|C}}==
<
#include <ctype.h>
Line 634 ⟶ 783:
return 0;
}</
Output is the same as everyone else's.
=={{header|C sharp|C#}}==
<
public class ReverseWordsInString
Line 664 ⟶ 813:
}
}
}</
=={{header|C++}}==
<
#include <algorithm>
#include <functional>
Line 728 ⟶ 877:
return 0;
}
</syntaxhighlight>
===Alternate version===
<
#include <string>
#include <iostream>
Line 772 ⟶ 921:
return system( "pause" );
}
</syntaxhighlight>
=={{header|Clojure}}==
<
(def poem
"---------- Ice and Fire ------------
Line 790 ⟶ 939:
(dorun
(map println (map #(apply str (interpose " " (reverse (re-seq #"[^\s]+" %)))) (clojure.string/split poem #"\n"))))
</syntaxhighlight>
Output is the same as everyone else's.
=={{header|COBOL}}==
<syntaxhighlight lang="cobol">
program-id. rev-word.
data division.
Line 857 ⟶ 1,006:
.
end program rev-word.
</syntaxhighlight>
{{out}}
<pre>
Line 874 ⟶ 1,023:
=={{header|CoffeeScript}}==
{{trans|JavaScript}}
<
fire, in end will world the say Some\n
ice. in say Some\n
Line 885 ⟶ 1,034:
s.split('\n').map((l) -> l.split(/\s/).reverse().join ' ').join '\n'
console.log reverseString(strReversed)</
{{out}}
As JavaScript.
=={{header|Common Lisp}}==
<
(labels
((iter (s lst)
Line 918 ⟶ 1,067:
(loop for line = (read-line s NIL)
while line
do (format t "~{~a~#[~:; ~]~}~%" (split-and-reverse line))))</
Output is the same as everyone else's.
=={{header|D}}==
<
import std.stdio, std.string, std.range, std.algorithm;
Line 940 ⟶ 1,089:
writefln("%(%-(%s %)\n%)",
text.splitLines.map!(r => r.split.retro));
}</
The output is the same as the Python entry.
=={{header|Delphi}}==
<syntaxhighlight lang="delphi">program RosettaCode_ReverseWordsInAString;
{$APPTYPE CONSOLE}
uses Classes, Types, StrUtils;
const
TXT =
'---------- Ice and Fire -----------'+sLineBreak+
sLineBreak+
'fire, in end will world the say Some'+sLineBreak+
'ice. in say Some'+sLineBreak+
'desire of tasted I''ve what From'+sLineBreak+
'fire. favor who those with hold I'+sLineBreak+
sLineBreak+
'... elided paragraph last ...'+sLineBreak+
sLineBreak+
'Frost Robert -----------------------'+sLineBreak;
var
i, w: Integer;
d: TStringDynArray;
begin
with TStringList.Create do
try
Text := TXT;
for i := 0 to Count - 1 do
begin
d := SplitString(Strings[i], #32);
Strings[i] := '';
for w := Length(d) - 1 downto 0 do
Strings[i] := Strings[i] + #32 + d[w];
end;
Writeln(Text);
finally
Free
end;
ReadLn;
end.</syntaxhighlight>
The output is the same as the Pascal entry.
=={{header|EasyLang}}==
<syntaxhighlight>
repeat
s$ = input
until error = 1
s$[] = strsplit s$ " "
for i = len s$[] downto 1
write s$[i] & " "
.
print ""
.
input_data
--------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------
</syntaxhighlight>
=={{header|EchoLisp}}==
Using a here-string input :
<
(define S #<<
---------- Ice and Fire ------------
Line 962 ⟶ 1,176:
(for/list ((line (string-split S "\n")))
(string-join (reverse (string-split line " ")) " ")))
</syntaxhighlight>
{{out}}
<pre>
Line 978 ⟶ 1,192:
=={{header|Elena}}==
ELENA
<
import system'routines;
Line 995 ⟶ 1,209:
"Frost Robert -----------------------"};
text.forEach::(line)
{
line.splitBy
{
console.print(word," ")
Line 1,003 ⟶ 1,217:
console.writeLine()
}
}</
=={{header|Elixir}}==
<
def reverse_words(txt) do
txt |> String.split("\n") # split lines
Line 1,015 ⟶ 1,229:
|> Enum.join("\n") # rejoin lines
end
end</
Usage:
<
---------- Ice and Fire ------------
Line 1,030 ⟶ 1,244:
"""
IO.puts RC.reverse_words(txt)</
=={{header|Elm}}==
<
reversedPoem =
String.trim """
Line 1,057 ⟶ 1,271:
poem =
reverseLinesWords reversedPoem
</syntaxhighlight>
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(defun reverse-words (line)
(insert
(format "%s\n"
Line 1,080 ⟶ 1,293:
"... elided paragraph last ..."
""
"Frost Robert ----------------------- "))</syntaxhighlight>
{{out}}
<pre>
------------ Fire and Ice ----------
Line 1,096 ⟶ 1,310:
</pre>
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
//Reverse words in a string. Nigel Galloway: July 14th., 2021
[" ---------- Ice and Fire ------------ ";
" ";
" fire, in end will world the say Some ";
" ice. in say Some ";
" desire of tasted I've what From ";
" fire. favour who those with hold I ";
" ";
" ... elided paragraph last ... ";
" ";
" Frost Robert ----------------------- "]|>List.map(fun n->n.Split " "|>Array.filter((<>)"")|>Array.rev|>String.concat " ")|>List.iter(printfn "%s")
</syntaxhighlight>
{{out}}
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favour fire.
... last paragraph elided ...
----------------------- Robert Frost
</pre>
=={{header|Factor}}==
<
IN: rosetta-code.reverse-words
Line 1,111 ⟶ 1,352:
Frost Robert -----------------------"
"\n" split [ " " split reverse " " join ] map [ print ] each</
{{out}}
<pre>
Line 1,128 ⟶ 1,369:
=={{header|Forth}}==
The word "parse-name" consumes a word from input stream and places it on the stack. The word "type" takes a word from the data stack and prints it. Calling these two words before and after the recursive call effectively reverses a string.
<syntaxhighlight lang="text">: not-empty? dup 0 > ;
: (reverse) parse-name not-empty? IF recurse THEN type space ;
: reverse (reverse) cr ;
Line 1,141 ⟶ 1,382:
reverse ... elided paragraph last ...
reverse
reverse Frost Robert -----------------------</
'''Output'''
Line 1,162 ⟶ 1,403:
Fortran syntax is mostly Fortran 77.
<
character*40 words
character*40 reversed
Line 1,191 ⟶ 1,432:
end
</syntaxhighlight>
Output from comand: <b>cat frostPoem.txt | reverse</b><p>
Line 1,212 ⟶ 1,453:
=={{header|FreeBASIC}}==
<
Sub split (s As String, sepList As String, result() As String, removeEmpty As Boolean = False)
Line 1,263 ⟶ 1,504:
Print
Print "Press any key to quit"
Sleep</
{{out}}
Line 1,272 ⟶ 1,513:
=={{header|Frink}}==
<
lines=split["\n",
"""---------- Ice and Fire ------------
Line 1,287 ⟶ 1,528:
for line = lines
println[join[" ", reverse[split[%r/\s+/, line]]]]
</syntaxhighlight>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
CFStringRef frostStr
CFArrayRef frostArr, tempArr
CFMutableStringRef mutStr
NSInteger i, count
frostStr = @"---------- Ice and Fire ------------\n¬
\n¬
fire, in end will world the say Some\n¬
ice. in say Some\n¬
desire of tasted I've what From\n¬
fire. favor who those with hold I\n¬
\n¬
… elided paragraph last …\n¬
\n¬
Frost Robert -----------------------\n"
frostArr = fn StringComponentsSeparatedByString( frostStr, @"\n" )
count = fn ArrayCount( frostArr )
mutStr = fn MutableStringWithCapacity( 0 )
for i = 0 to count - 1
tempArr = fn StringComponentsSeparatedByString( frostArr[i], @" " )
tempArr = fn EnumeratorAllObjects( fn ArrayReverseObjectEnumerator( tempArr ) )
MutableStringAppendString( mutStr, fn ArrayComponentsJoinedByString( tempArr, @" " ) )
MutableStringAppendString( mutStr, @"\n" )
next
NSLog( @"%@", mutStr )
HandleEvents
</syntaxhighlight>
Output:
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
… last paragraph elided …
----------------------- Robert Frost
</pre>
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=c81c1bbf94e856035fd382015d208272 Click this link to run this code]'''
<
Dim sString As New String[10] 'Array for the input text
Dim sLine As New String[] 'Array of each word in a line
Line 1,326 ⟶ 1,617:
Print sOutput 'Print the output
End</
Output:
<pre>
Line 1,342 ⟶ 1,633:
=={{header|Gema}}==
<
=={{header|Go}}==
<
import (
Line 1,380 ⟶ 1,671:
fmt.Println(t)
}
}</
{{out}}
<pre>
Line 1,396 ⟶ 1,687:
=={{header|Groovy}}==
<
.append('---------- Ice and Fire ------------\n')
.append(' \n')
Line 1,410 ⟶ 1,701:
text.eachLine { line ->
println "$line --> ${line.split(' ').reverse().join(' ')}"
}</
{{output}}
<pre>---------- Ice and Fire ------------ --> ------------ Fire and Ice ----------
Line 1,424 ⟶ 1,715:
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">
revstr :: String -> String
revstr = unwords . reverse . words -- point-free style
Line 1,443 ⟶ 1,734:
\\n\
\Frost Robert -----------------------\n" --multiline string notation requires \ at end and start of lines, and \n to be manually input
</syntaxhighlight>
unwords, reverse, words, unlines, map and lines are built-in functions, all available at GHC's Prelude.
For better visualization, use "putStr test"
Line 1,450 ⟶ 1,741:
Works in both languages:
<
every write(rWords(&input))
end
Line 1,463 ⟶ 1,754:
procedure genWords()
while w := 1(tab(upto(" \t")),tab(many(" \t"))) || " " do suspend w
end</
{{out}} for test file:
Line 1,480 ⟶ 1,771:
->
</pre>
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(var poem
"---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------")
(function split-join by then x
(-> x (split by) then (join by)))
(split-join "\n" (map @(split-join " " reverse)) poem)</syntaxhighlight>
=={{header|J}}==
Line 1,485 ⟶ 1,794:
Treated interactively:
<
---------- Ice and Fire ------------
Line 1,507 ⟶ 1,816:
----------------------- Robert Frost
</syntaxhighlight>
The verb phrase <code>( [: ; @ |. [: < ;. 1 ' ' , ])</code> reverses words in a string. The rest of the implementation has to do with defining the block of text we are working on, and applying this verb phrase to each line of that text.
Another approach:
<syntaxhighlight lang="j">echo ;:inv@|.@cut;._2 {{)n
---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------
}}</syntaxhighlight>
produces:
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
... last paragraph elided ...
----------------------- Robert Frost
</pre>
=={{header|Java}}==
<
static final String[] lines = {
Line 1,533 ⟶ 1,872:
}
}
}</
{{works with|Java|8+}}
<
import static java.util.Arrays.stream;
Line 1,573 ⟶ 1,912:
;
}
}</
{{out}}
Line 1,589 ⟶ 1,928:
=={{header|JavaScript}}==
<
"---------- Ice and Fire ------------\n\
\n\
Line 1,611 ⟶ 1,950:
console.log(
reverseString(strReversed)
);</
Output:
Line 1,626 ⟶ 1,965:
=={{header|jq}}==
<
This solution requires a version of jq with regex support for split.
The following example assumes the above line is in a file named reverse_words.jq and that the input text is in a file named IceAndFire.txt. The -r option instructs jq to read the input file as strings, line by line.<
------------ Fire and Ice ----------
Line 1,639 ⟶ 1,978:
... last paragraph elided ...
----------------------- Robert Frost</
=={{header|Jsish}}==
From Javascript entry.
<
"---------- Ice and Fire ------------\n
fire, in end will world the say Some
Line 1,688 ⟶ 2,027:
----------------------- Robert Frost
=!EXPECTEND!=
*/</
{{out}}
Line 1,696 ⟶ 2,035:
=={{header|Julia}}==
<
<pre>julia> revstring("Hey you, Bub!")
"Bub! you, Hey"
Line 1,727 ⟶ 2,066:
=={{header|Kotlin}}==
<
fun main() {
Line 1,746 ⟶ 2,085:
)
sl.forEach { println(reversedWords(it)) }
}</
{{out}}
Line 1,763 ⟶ 2,102:
----------------------- Robert Frost
</pre>
=={{header|Ksh}}==
<syntaxhighlight lang="ksh">
#!/bin/ksh
# Reverse words in a string
# # Variables:
#
typeset -a wArr
integer i
######
# main #
######
while read -A wArr; do
for ((i=${#wArr[@]}-1; i>=0; i--)); do
printf "%s " "${wArr[i]}"
done
echo
done << EOF
---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------
EOF</syntaxhighlight>
{{out}}<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
... last paragraph elided ...
----------------------- Robert Frost </pre>
=={{header|Lambdatalk}}==
This answer illustrates how a missing primitive (line_split) can be added directly in the wiki page.
<
1) We write a function
Line 1,835 ⟶ 2,217:
----------------------- Robert Frost
</syntaxhighlight>
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
for i = 1 to 10
read string$
Line 1,865 ⟶ 2,247:
data ""
data "Frost Robert -----------------------"
</syntaxhighlight>
{{Out}}
<pre>------------ Fire and Ice ----------
Line 1,880 ⟶ 2,262:
=={{header|LiveCode}}==
The input text has been entered into the contents of a text field called "Fieldtxt", add a button and put the following in its mouseUp
<
repeat with i = the number of words of txtln down to 1
put word i of txtln & space after txtrev
Line 1,886 ⟶ 2,268:
put cr after txtrev -- preserve line
end repeat
put txtrev</
=={{header|LiveScript}}==
<
poem =
"""
Line 1,907 ⟶ 2,289:
reverse-string = (.split '\n') >> (.map reverse-words) >> (.join '\n')
reverse-string poem
</syntaxhighlight>
=={{header|Logo}}==
This version just reads the words from standard input.
<
make "line readlist
print reverse :line
] [word? :line]
bye</
{{Out}}
Line 1,945 ⟶ 2,327:
See below for original entry and the input string under variable 's'. Here is a significantly shorter program.
<
local lines = {}
for line in (s .. "\n"):gmatch("(.-)\n") do
Line 1,955 ⟶ 2,337:
end
print(table.concat(lines, "\n"))
</syntaxhighlight>
Line 1,975 ⟶ 2,357:
]]
<
local res = {}
for i = #a, 1, -1 do
Line 1,993 ⟶ 2,375:
for line, nl in s:gmatch("([^\n]-)(\n)") do
print(table.concat(table.reverse(splittokens(line)), ' '))
end</
''Note:'' With the technique used here for splitting <code>s</code> into lines (not part of the task) the last line will be gobbled up if it does not end with a newline.
=={{header|Maple}}==
<
input := readline("input.txt"):
if input = 0 then break: fi:
Line 2,004 ⟶ 2,386:
input := StringTools:-Join(ListTools:-Reverse(StringTools:-Split(input, " "))," "):
printf("%s\n", input):
od:</
{{Out|Output}}
<pre>------------ Fire and Ice ----------
Line 2,017 ⟶ 2,399:
----------------------- Robert Frost</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
fire, in end will world the say Some
Line 2,033 ⟶ 2,415:
linesWithReversedWords =
StringJoin[Riffle[#, " "]] & /@ reversedWordArray;
finaloutput = StringJoin[Riffle[#, "\n"]] & @ linesWithReversedWords</
{{out}}
<pre>------------ Fire and Ice ----------
Line 2,047 ⟶ 2,429:
=={{header|MATLAB}} / {{header|Octave}}==
<
testStr = {'---------- Ice and Fire ------------' ; ...
'' ; ...
Line 2,071 ⟶ 2,453:
strOut = strtrim(sprintf('%s ', words{end:-1:1}));
end
end</
{{out}}
<pre>------------ Fire and Ice ----------
Line 2,085 ⟶ 2,467:
=={{header|MAXScript}}==
<
-- MAXScript : Reverse words in a string : N.H. 2019
--
Line 2,111 ⟶ 2,493:
) -- end of while eof
)
</syntaxhighlight>
{{out}}
Output to MAXScript Listener:
Line 2,126 ⟶ 2,508:
=={{header|MiniScript}}==
<
"| ---------- Ice and Fire ------------ |",
"| |",
Line 2,150 ⟶ 2,532:
end while
print newLine.join
end for</
{{out}}
<pre>
Line 2,170 ⟶ 2,552:
{{trans|Pascal}}
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<
MODULE ReverseWords;
Line 2,229 ⟶ 2,611:
END;
END ReverseWords.
</syntaxhighlight>
=={{header|Nanoquery}}==
<
tokens = split(string, " ")
if len(tokens) = 0
Line 2,257 ⟶ 2,639:
for line in split(data, "\n")
println reverse_words(line)
end</
{{out}}
<pre>------------ Fire and Ice ----------
Line 2,273 ⟶ 2,655:
{{works with|Q'Nial Version 6.3}}
<syntaxhighlight lang="nial">
# Define a function to convert a list of strings to a single string.
join is rest link (' ' eachboth link)
Line 2,292 ⟶ 2,674:
'' \
'Poe Edgar -----------------------'
</syntaxhighlight>
{{out}}
Line 2,311 ⟶ 2,693:
=={{header|Nim}}==
<
let text = """---------- Ice and Fire ------------
Line 2,337 ⟶ 2,719:
for line in text.splitLines():
echo line.split(' ').reversed().join(" ")</
{{out}}
<pre>------------ Fire and Ice ----------
Line 2,351 ⟶ 2,733:
=={{header|Objeck}}==
<
class Reverselines {
Line 2,379 ⟶ 2,761:
};
}
}</
{{out}}
Line 2,394 ⟶ 2,776:
=={{header|OCaml}}==
<
let input = ["---------- Ice and Fire ------------";
"";
Line 2,409 ⟶ 2,791:
let reversed = List.map List.rev splitted in
let final = List.map (String.concat " ") reversed in
List.iter print_endline final;;</
Sample usage
<pre>$ ocaml reverse.ml
Line 2,426 ⟶ 2,808:
=={{header|Oforth}}==
<
s words reverse unwords ;
Line 2,439 ⟶ 2,821:
"... elided paragraph last ... " revWords println
" " revWords println
"Frost Robert -----------------------" revWords println ;</
{{out}}
Line 2,459 ⟶ 2,841:
=={{header|Pascal}}==
Free Pascal 3.0.0
<
{$H+}
Line 2,504 ⟶ 2,886:
end;
readln;
end.</
{{out}}
<pre>----------- Fire and Ice ----------
Line 2,516 ⟶ 2,898:
----------------------- Robert Frost</pre>
Another version (tested with FPC 3.2.2)
<syntaxhighlight lang="pascal">
program reverse_words;
{$mode objfpc}{$h+}
uses
SysUtils;
function Reverse(a: TStringArray): TStringArray;
var
I, J: SizeInt;
t: Pointer;
begin
I := 0;
J := High(a);
while I < J do begin
t := Pointer(a[I]);
Pointer(a[I]) := Pointer(a[J]);
Pointer(a[J]) := t;
Inc(I);
Dec(J);
end;
Result := a;
end;
const
Input =
'---------- Ice and Fire -----------' + LineEnding +
'' + LineEnding +
'fire, in end will world the say Some' + LineEnding +
'ice. in say Some' + LineEnding +
'desire of tasted I''ve what From' + LineEnding +
'fire. favor who those with hold I' + LineEnding +
'' + LineEnding +
'... elided paragraph last ...' + LineEnding +
'' + LineEnding +
'Frost Robert -----------------------' + LineEnding;
var
Line: string;
begin
for Line in Input.Split([LineEnding], TStringSplitOptions.ExcludeLastEmpty) do
WriteLn(string.Join(' ', Reverse(Line.Split([' ']))));
end.
</syntaxhighlight>
=={{header|Perl}}==
<
__DATA__
---------- Ice and Fire ------------
Line 2,530 ⟶ 2,957:
Frost Robert -----------------------
</syntaxhighlight>
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">test</span><span style="color: #0000FF;">=</span><span style="color: #008000;">"""
---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------
"""</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">test</span><span style="color: #0000FF;">,</span><span style="color: #008000;">'\n'</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">lines</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])))</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">))</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 2,565 ⟶ 2,995:
=={{header|Phixmonti}}==
<
"---------- Ice and Fire ------------"
Line 2,587 ⟶ 3,017:
else drop endif
drop nl
endfor</
{{out}}
<pre>
Line 2,603 ⟶ 3,033:
=={{header|PHP}}==
<
<?php
Line 2,631 ⟶ 3,061:
echo strInv($string);</
'''Output''':
<
Some say the world will end in fire,
Line 2,643 ⟶ 3,073:
... last paragraph elided ...
----------------------- Robert Frost</
=={{header|PicoLisp}}==
<syntaxhighlight lang="picolisp">
(in "FireIce.txt"
(until (eof)
(prinl (glue " " (flip (split (line) " "))))))
</syntaxhighlight>
{{Out}}
Same as anybody else.
=={{header|Pike}}==
<
fire, in end will world the say Some
Line 2,668 ⟶ 3,098:
foreach(story/"\n", string line)
write("%s\n", reverse(line/" ")*" ");
</syntaxhighlight>
=={{header|PL/I}}==
<
declare (s, reverse) character (50) varying;
declare (i, j) fixed binary;
Line 2,703 ⟶ 3,133:
put edit ('---> ', reverse) (col(40), 2 A);
end;
end rev;</
{{out}}
<pre>
Line 2,720 ⟶ 3,150:
=={{header|PowerShell}}==
{{works with|PowerShell|4.0}}
<syntaxhighlight lang="powershell">
Function Reverse-Words($lines) {
$lines | foreach {
Line 2,741 ⟶ 3,171:
Reverse-Words($lines)
</syntaxhighlight>
'''output''' :
Line 2,758 ⟶ 3,188:
=={{header|PureBasic}}==
<
" " +#CRLF$+
"fire, in end will world the say Some" +#CRLF$+
Line 2,779 ⟶ 3,209:
Next
Input()
</syntaxhighlight>
{{out}}
<pre>
Line 2,797 ⟶ 3,227:
=={{header|Python}}==
<
---------- Ice and Fire ------------
Line 2,809 ⟶ 3,239:
Frost Robert -----------------------'''
for line in text.split('\n'): print(' '.join(line.split()[::-1]))</
'''Output''':
<
Some say the world will end in fire,
Line 2,822 ⟶ 3,252:
... last paragraph elided ...
----------------------- Robert Frost</
=={{header|Quackery}}==
<
$ ""
$ " fire, in end will world the say Some "
Line 2,841 ⟶ 3,271:
witheach
[ echo$ sp ]
cr ]</
{{out}}
Line 2,858 ⟶ 3,288:
=={{header|R}}==
<syntaxhighlight lang="r">
whack <- function(s) {
paste( rev( unlist(strsplit(s, " "))), collapse=' ' ) }
Line 2,877 ⟶ 3,307:
for (line in poem) cat( whack(line), "\n" )
</syntaxhighlight>
{{out}}
Line 2,898 ⟶ 3,328:
(Everything that happens in R is a function-call.)
<syntaxhighlight lang="r">
> `{` <- function(s) rev(unlist(strsplit(s, " ")))
> {"one two three four five"}
[1] "five" "four" "three" "two" "one"
</syntaxhighlight>
You had better restart your REPL after trying this.
=={{header|Racket}}==
<
(require racket/string)
Line 2,934 ⟶ 3,364:
(begin (displayln (split-reverse l))
(loop (read-line poem-port))))))
</syntaxhighlight>
In Wheeler-readable/sweet notation (https://readable.sourceforge.io/) as implemented by Asumu Takikawa (https://github.com/takikawa/sweet-racket):
<syntaxhighlight lang="racket">
#lang sweet-exp racket/base
require racket/string
define split-reverse(str)
string-join $ reverse $ string-split str
define poem
"---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------"
let
\\
poem-port $ open-input-string poem
let loop
\\
l $ read-line poem-port
unless eof-object?(l)
begin
displayln split-reverse(l)
loop read-line(poem-port)
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
We'll read input from stdin
<syntaxhighlight lang="raku"
{{out}}
<pre>------------ Fire and Ice ----------
Line 2,953 ⟶ 3,415:
=={{header|Red}}==
<
foreach line
split
Line 2,968 ⟶ 3,430:
print reverse split line " "
]
</syntaxhighlight>
=={{header|REXX}}==
===natural order===
This REXX version process the words in a natural order (first to last).
<
@.=; @.1 = "---------- Ice and Fire ------------"
@.2 = ' '
Line 2,992 ⟶ 3,454:
say $ /*display the newly constructed line. */
end /*j*/ /*stick a fork in it, we're all done. */</
'''output''' when using the (internal text) ten lines of input:
<pre>
Line 3,009 ⟶ 3,471:
===reverse order===
This REXX version process the words in reverse order (last to first).
<
@.=; @.1 = "---------- Ice and Fire ------------"
@.2 = ' '
Line 3,028 ⟶ 3,490:
say $ /*display the newly constructed line. */
end /*j*/ /*stick a fork in it, we're all done. */</
'''output''' is the same as the 1<sup>st</sup> REXX version. <br><br>
=={{header|Ring}}==
<
aList = str2list("
---------- Ice and Fire ------------
Line 3,050 ⟶ 3,512:
for y in aList2 see y + " " next see nl
next
</syntaxhighlight>
Output
<
------------ Fire and Ice ----------
Line 3,063 ⟶ 3,525:
... last paragraph elided ...
----------------------- Robert Frost
</syntaxhighlight>
=={{header|RPL}}==
« { }
'''WHILE''' OVER " " POS '''REPEAT'''
LASTARG → sep
« OVER 1 sep SUB +
SWAP sep 1 + OVER SIZE SUB SWAP
»
'''END'''
SWAP + REVLIST
'''IFERR''' ∑LIST '''THEN''' 1 GET '''END'''
» '<span style="color:blue">REVWORDS</span>' STO
{ "---------- Ice and Fire ------------" "" "fire, in end will world the say Some" "ice. in say Some" "desire of tasted I've what From" "fire. favor who those with hold I" "" "... elided paragraph last ..." "" "Frost Robert -----------------------" }
1 « <span style="color:blue">REVWORDS</span> » DOLIST
{{out}}
<pre>
1: { "------------ Fire and Ice ----------"
""
"Some say the world will end in fire,"
"Some say in ice."
"From what I've tasted of desire"
"I hold with those who favor fire."
""
"... last paragraph elided ..."
""
"----------------------- Robert Frost" }
</pre>
=={{header|Ruby}}==
<
---------- Ice and Fire ------------
Line 3,078 ⟶ 3,569:
Frost Robert -----------------------
EOS
.each_line.map {|line| line.split.reverse.join(' ')}</
Output the same as everyone else's.
=={{header|Run BASIC}}==
<
read string$
j = 1
Line 3,104 ⟶ 3,595:
data "... elided paragraph last ..."
data ""
data "Frost Robert -----------------------"</
Output:
<pre>------------ Fire and Ice ----------
Line 3,118 ⟶ 3,609:
=={{header|Rust}}==
<
"---------- Ice and Fire ------------
Line 3,140 ⟶ 3,631:
.collect::<Vec<_>>() // Collect lines into Vec<String>
.join("\n")); // Concatenate lines into String
}</
=={{header|S-lang}}==
<
["---------- Ice and Fire ------------",
"fire, in end will world the say Some",
Line 3,158 ⟶ 3,649:
array_reverse(ln);
() = printf("%s\n", strjoin(ln, " "));
}</
{{out}}
<pre>------------ Fire and Ice ----------
Line 3,173 ⟶ 3,664:
{{works with|Scala|2.9.x}}
<
"""| ---------- Ice and Fire ------------
Line 3,189 ⟶ 3,680:
.foreach{println}
}</
{{out}}
Line 3,208 ⟶ 3,699:
{{works with|Gauche Scheme}}
<syntaxhighlight lang="scheme">
(for-each
(lambda (s) (print (string-join (reverse (string-split s #/ +/)))))
Line 3,223 ⟶ 3,714:
Frost Robert -----------------------"
#/[ \r]*\n[ \r]*/))
</syntaxhighlight>
<b>Output:</b>
<pre>
Line 3,239 ⟶ 3,730:
=={{header|sed}}==
<
G
Line 3,245 ⟶ 3,736:
s/^[[:space:]]*\([^[:space:]][^[:space:]]*\)\(.*\n\)/\2 \1/
t loop
s/^[[:space:]]*//</
=={{header|Seed7}}==
<
const array string: lines is [] (
Line 3,275 ⟶ 3,766:
writeln;
end for;
end func;</
{{out}}
Line 3,289 ⟶ 3,780:
----------------------- Robert Frost
</pre>
=={{header|SenseTalk}}==
<syntaxhighlight lang="sensetalk">set poem to {{
---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------
}}
repeat with each line in poem
put (each word of it) reversed joined by space
end repeat
</syntaxhighlight>
{{out}}
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
... last paragraph elided ...
----------------------- Robert Frost
</pre>
=={{header|Sidef}}==
<
__DATA__
Line 3,304 ⟶ 3,827:
... elided paragraph last ...
Frost Robert -----------------------</
=={{header|Smalltalk}}==
<
poem := '---------- Ice and Fire ------------
Line 3,320 ⟶ 3,843:
(poem lines collect: [ :line | ((line splitOn: ' ') reverse) joinUsing: ' ' ]) joinUsing: (String cr).
</syntaxhighlight>
{{out}}
Line 3,340 ⟶ 3,863:
This only considers space as the word separator, not tabs, form feeds or any other sort of whitespace. (This, however, turns out not to be an issue with the example input.)
<
fire, in end will world the say Some
Line 3,359 ⟶ 3,882:
print();
});</
=={{header|Standard ML}}==
<
" ---------- Ice and Fire ------------ ",
" ",
Line 3,377 ⟶ 3,900:
val revWords = String.concatWith " " o rev o String.tokens Char.isSpace
val () = app (fn line => print (revWords line ^ "\n")) lines</
=={{header|Swift}}==
<
// convenience extension for better clarity
Line 3,400 ⟶ 3,923:
let output = input.lines.map { $0.words.reverse().joinWithSeparator(" ") }.joinWithSeparator("\n")
print(output)</
{{out}}
<pre>
Line 3,416 ⟶ 3,939:
=={{header|Tailspin}}==
<
def input: ['---------- Ice and Fire ------------',
'',
Line 3,436 ⟶ 3,959:
$input... -> '$ -> words -> $(last..first:-1)...;
' -> !OUT::write
</syntaxhighlight>
=={{header|Tcl}}==
<
"---------- Ice and Fire ------------"
""
Line 3,455 ⟶ 3,978:
# This would also work for data this simple:
### puts [lreverse $line]
}</
{{out}}
<pre>
Line 3,471 ⟶ 3,994:
Alternatively…
{{works with|Tcl|8.6}}
<
=={{header|TXR}}==
Run from command line:
<syntaxhighlight lang
'''Solution:'''
<
@ (some)
@(coll)@{words /[^ ]+/}@(end)
Line 3,490 ⟶ 4,013:
@ (end)
@(end)
</syntaxhighlight>
New line should be present after the last @(end) terminating vertical definition.
i.e.
<
[EOF]</
not
<syntaxhighlight lang
=={{header|UNIX Shell}}==
{{works with|bash}}
<
for ((i=${#words[@]}-1; i>=0; i--)); do
printf "%s " "${words[i]}"
Line 3,516 ⟶ 4,039:
Frost Robert -----------------------
END</
{{works with|ksh}}
Same as above, except change <
=={{header|VBA}}==
<syntaxhighlight lang="vb">
Option Explicit
Line 3,559 ⟶ 4,082:
ReverseLine = Join(R, Separat)
End If
End Function</
{{Out}}
<pre>------------- Fire And Ice -------------
Line 3,573 ⟶ 4,096:
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
Option Explicit
Line 3,613 ⟶ 4,136:
objOutFile.Close
Set objFSO = Nothing
</syntaxhighlight>
{{Out}}
Line 3,626 ⟶ 4,149:
... last paragraph elided ...
----------------------- Robert Frost
</pre>
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">fn main() {
mut n := [
"---------- Ice and Fire ------------",
" ",
"fire, in end will world the say Some",
"ice. in say Some ",
"desire of tasted I've what From ",
"fire. favor who those with hold I ",
" ",
"... elided paragraph last ... ",
" ",
"Frost Robert -----------------------",
]
for i, s in n {
mut t := s.fields() // tokenize
// reverse
last := t.len - 1
for j, k in t[..t.len/2] {
t[j], t[last-j] = t[last-j], k
}
n[i] = t.join(" ")
}
// display result
for t in n {
println(t)
}
}</syntaxhighlight>
'''Simpler version:'''
<syntaxhighlight lang="vlang">mut n := [
"---------- Ice and Fire ------------",
" ",
"fire, in end will world the say Some",
"ice. in say Some ",
"desire of tasted I've what From ",
"fire. favor who those with hold I ",
" ",
"... elided paragraph last ... ",
" ",
"Frost Robert -----------------------",
]
println(
n.map(
it.fields().reverse().join(' ').trim_space()
).join('\n')
)</syntaxhighlight>
{{out}}
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
... last paragraph elided ...
----------------------- Robert Frost
Line 3,631 ⟶ 4,219:
=={{header|Wren}}==
<
"---------- Ice and Fire ------------",
" ",
Line 3,648 ⟶ 4,236:
tokens = tokens[-1..0]
System.print(tokens.join(" "))
}</
{{out}}
Line 3,661 ⟶ 4,249:
... last paragraph elided ...
----------------------- Robert Frost
</pre>
=={{header|XBS}}==
<syntaxhighlight lang="xbs">func revWords(x:string=""){
(x=="")&=>send x+"<br>";
set sp = x::split(" ");
send sp::reverse()::join(" ");
}
set lines:array=[
"---------- Ice and Fire ------------",
"",
"fire, in end will world the say Some",
"ice. in say Some",
"desire of tasted I've what From",
"fire. favor who those with hold I",
"",
"... elided paragraph last ...",
"",
"Frost Robert -----------------------",
];
foreach(v of lines){
log(revWords(v));
}</syntaxhighlight>
{{out}}
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
... last paragraph elided ...
----------------------- Robert Frost
</pre>
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">string 0;
def LF=$0A, CR=$0D;
proc Reverse(Str, Len); \Reverse order of chars in string
char Str; int Len;
int I, J, T;
[I:= 0;
J:= Len-1;
while I < J do
[T:= Str(I); Str(I):= Str(J); Str(J):= T;
I:= I+1; J:= J-1;
];
];
char Str;
int I, LineBase, WordBase;
[Str:=
"---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------";
I:= 0;
repeat LineBase:= I;
loop [WordBase:= I;
repeat I:= I+1 until Str(I) <= $20;
Reverse(@Str(WordBase), I-WordBase);
if Str(I)=CR or Str(I)=LF or Str(I)=0 then quit;
I:= I+1; \skip space
];
Reverse(@Str(LineBase), I-LineBase);
while Str(I)=CR or Str(I)=LF do I:= I+1;
until Str(I) = 0;
Text(0, Str);
CrLf(0);
]</syntaxhighlight>
{{out}}
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
... last paragraph elided ...
----------------------- Robert Frost
</pre>
=={{header|Yabasic}}==
<
data " "
data " fire, in end will world the say Some "
Line 3,690 ⟶ 4,372:
break
end if
loop</
=={{header|zkl}}==
<
#<<<
"---------- Ice and Fire ------------
Line 3,709 ⟶ 4,391:
text.pump(11,Data,fcn(s){ // process stripped lines
s.split(" ").reverse().concat(" ") + "\n" })
.text.print();</
{{out}}
<pre>
|