# Reverse stdin and place on stdout

Requirements:

• Take an input on stdin including new lines / carriage returns of unlimited length (only bounded by system memory; that is, there is no inherent limit in the program.)
• Output the reverse of the input on stdout.

Example:

Input:

Quick brown fox
He jumped over the lazy dog

Output:

god yzal eht revo depmuj eH
xof nworb kciuQ

Shortest wins.

• Do you allow standard library functions like PHP strrev – Ming-Tang Jan 31 '11 at 6:46
• Is the output allowed to put the input's last newline at the beginning instead of the end? – Joey Adams Feb 2 '11 at 18:33
• @Joey Adams, yep, it should replicate the input exactly. – Thomas O Feb 2 '11 at 21:20
• Your example is somewhat wrong. The reverse of your input would be: ƃop ʎzɐʃ ǝɥʇ ɹǝʌo pǝdɯnɾ ǝH xoɟ uʍoɹq ʞɔınΌ ;-P – ninjalj Feb 4 '11 at 22:40
• Need I only support characters which can be input into the system executing the code? – Golden Ratio Mar 3 '17 at 11:34

x:1
y:''
Wx,]getchar,y,x+,x
oy

Try it online!

Fairly basic, although STDIN support was recently added to Add++, so I decided to show it off.

First, we set the two variables we need:

x:1
y:''

x to the integer 1 and y to the empty string. Next, we loop over each character in STDIN:

Wx,]getchar,y,x+,x

This is a while loop, with the condition simply being x. Each , denotes the separation of a new command, so the code is expanded into

Wx,
]getchar
y
x+
x

]getchar is an additional, Add++ jargon for an extended command that is prefixed with a ]. Here, it simply reads a character from STDIN and assigns that to x. If the end of STDIN is reached, an empty string is returned.

Next, with

y
x+
x

We prepend this character to y, effectively building the string in reverse.

Once all input has been read, the x variable contains the empty string, and the while loop is terminated. Then we reach the final command

oy

This uses prefix notation: o is the command, and y indicates the variable to operate here. Here, o means output, without a trailing newline. y contains the input reversed, so this outputs our final result.

# Pepe, 16 bytes

REEeREEEEeEeeReee

Try it online! (Compiler makes whitespaces when doing links between e and r)

Explanation:

REEeREEEEeEeeReee - full program

REEe              - insert input as string
REEEEeEee     - reverse whole stack
Reee - output

~ilj~#
>dko@

This one will function properly when NULs are on the input.

Try it online!

# PowerShell, 38 bytes

Thanks to Joey for the $($input) expression.

$($input)-join'
'|% t*y|%{$s=$_+$s}$s

Try it online!

## Alternative, 38 bytes

@($input)-join' '|% t*y|%{$s=$_+$s}
\$s

Try it online!

RVq

Try it online!

# Brain-Flak, 12 bytes

{({}<>)<>}<>

Not going to be winning with this, but it works

Try it Online!

# Rust, 57 bytes

fn q(s:&str)->String{s.chars().rev().collect::<String>()}

Try it online!

# Dart, 34 bytes

f(s)=>s.split('').reversed.join();

Try it online!

Pretty convoluted, you have to get a String List then reverse it and join it back for it to work.

# Triangular, 14 bytes

(\~(#vp]<./)?<

Try it online!

I am almost 100% certain that ,~#n^`>p/ (9 bytes) would work if IP switches behaved in accordance with their specification, but in the meantime, 14 ain't too shabby.

Ungolfed:

(
\ ~
( # v
p ] < .
/ ) ? <
----------------------------------------------
~v<             Read a character from input, change directions twice
?)/          ) returns to the previously set point. ? will skip the jump back if ToS < 0
p(        Pop the top value of the stack (the null-input), then set a new jump point
/#<[    Pop the top value of the stack and print that value, then jump back if ToS > 0