67
\$\begingroup\$

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.

Leaderboard:

var QUESTION_ID=242,OVERRIDE_USER=61563;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
8
  • 5
    \$\begingroup\$ Do you allow standard library functions like PHP strrev \$\endgroup\$
    – Ming-Tang
    Jan 31, 2011 at 6:46
  • 1
    \$\begingroup\$ Is the output allowed to put the input's last newline at the beginning instead of the end? \$\endgroup\$
    – Joey Adams
    Feb 2, 2011 at 18:33
  • 1
    \$\begingroup\$ @Joey Adams, yep, it should replicate the input exactly. \$\endgroup\$
    – Thomas O
    Feb 2, 2011 at 21:20
  • 63
    \$\begingroup\$ 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 \$\endgroup\$
    – ninjalj
    Feb 4, 2011 at 22:40
  • 3
    \$\begingroup\$ Your example is somewhat wrong. The reverse of your input would be: The slow purple fox She crawled below the diligent cat \$\endgroup\$ Aug 18, 2020 at 5:10

140 Answers 140

3
\$\begingroup\$

Perl

print scalar reverse for reverse(<STDIN>);
\$\endgroup\$
3
\$\begingroup\$

Fission, 20 15 bytes

KX$ \
!
SR?J%
~

The algorithm is very similar to Martin's, but the implementation differs significantly.

How it works

Everything starts at R, which releases an eastward atom with mass 1 and energy 0.

Upon hitting ?, an input character is saved as the atom's mass, and the energy is left at 0 unless stdin returns EOF, in which case energy becomes 1.

J is Fission's jump command, and jumps an atom forward a number of cells equivalent to its current energy, leaving the atom with 0 energy. For now, our atom has 0 energy and ignores this command.

We then strike %, which is a switch. With greater than 0 energy, our atom would be directed down (as if reflected by an \ mirror), but since we have exactly 0 energy, we are sent upwards by the opposite mirror, /.

Our atom continues until it strikes a second mirror, \ this time directing it left.

We increment the atom's energy to 1 with $, and use X to duplicate the atom. One copy will reflect back on to the $ command (leaving that copy with 2 energy) and the other copy will be pushed on to the stack, K.

Our reflected copy travels backwards from whence it came until it hits the % switch again. Now that we have a positive energy, we reflect as if we had hit an \ mirror, wrapping around the board onto the next S and decrementing our energy to 1.

The S command will consume 1 energy to preserve our direction. Had we no energy, the atom would have deflected as if struck by an \ mirror, downward. Instead, we move to the right again and pick up more input with ? and the cycle repeats.

Once our atom reaches EOF, the ? command will store 1 energy in the atom. Thus, when we hit the J command this time, we completely skip over the % switch and land on the S switch with 0 energy.

Now, since our energy was consumed in the jump, our direction is not preserved by the S switch, but we are rather directed downward. We then decrement our energy to -1 with the ~ command and wrap around the board. When hit with a negative energy, the K command pops an atom instead of pushing one. We output our newly popped atom with !, and use the 1 energy of that atom to bypass the S switch, and the cycle completes.

If the stack K was empty, our atom's energy is negated (resulting in +1 energy) and it is reflected back onto the ~ command, leaving it with energy 0. Upon hitting S again, we are deflected to the right, until the ? is struck. Since EOF has been reached, the ? destroys the atom and terminates the program.

\$\endgroup\$
3
\$\begingroup\$

awk, 24 bytes

Field separator set to '' means that each char is in its own field and we can use NF as iterator from end to begining. To break record barriers, RS is also '' meaning record ends at first empty record (\n\n).

{for(;NF-->0;)printf$NF}

Execution ends in an error as the NF-- reaches -1 and awk can't handle that. It could be handled with 2 more bytes to change the for(;NF-->0;) to for(;NF>0;NF--). Test it:

$ awk -F '' -v RS='' '{for(;NF-->0;)printf$NF}' file
od yzal eht revo depmuj eH
xof nworb kciuQawk: cmd. line:1: (FILENAME=asd FNR=1) fatal: NF set to negative value
\$\endgroup\$
3
\$\begingroup\$

Perl 6, 16 bytes

print slurp.flip

slurp reads the input as a single string, and flip reverses it.

say is more common for output, but that introduces an extra newline that wasn't in the input.

\$\endgroup\$
3
\$\begingroup\$

GameMaker Language, 90 89 82 Characters

No built-in reverse functions.

s=r=argument0;for(l=string_length(r);i<r;i++){c=string_char_at(s,l-i)o+=c}return o

Compile with all uninitialized variables as 0

\$\endgroup\$
2
  • \$\begingroup\$ Link to this language? \$\endgroup\$
    – MD XF
    Sep 19, 2017 at 3:31
  • \$\begingroup\$ @MDXF You can download Game Maker 8.1 Lite or the free version of GM Studio if you want to try this out. \$\endgroup\$
    – Timtech
    Sep 19, 2017 at 11:57
3
\$\begingroup\$

05AB1E, 1 byte

R

R reverses the input.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Thanks for using 05AB1E :). You don't need the , at the end, because the top of the stack is printed automatically when nothing has printed. \$\endgroup\$
    – Adnan
    Apr 26, 2016 at 21:13
  • \$\begingroup\$ @Adnan Thanks for the tip. \$\endgroup\$
    – penalosa
    Apr 26, 2016 at 21:36
  • 1
    \$\begingroup\$ This answer doesn't handle newlines. \$\endgroup\$
    – Makonede
    Dec 10, 2020 at 23:14
3
\$\begingroup\$

Keg, 1 byte

?

Try it online!

Print reversed input implicitly

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Doesn't work if there's any newlines in the input \$\endgroup\$
    – Jo King
    Oct 27, 2019 at 12:05
3
\$\begingroup\$

Javascript (Node.js), 89 bytes

-6 bytes thanks to bbrk24

Finally a JS answer that actually uses stdin and stdout.

s='';process.stdin.on('data',d=>s+=d).on('end',_=>console.log([...s].reverse().join('')))
\$\endgroup\$
1
  • \$\begingroup\$ I think you can chain calls to .on, so the assignment of r is unnecessary: process.stdin.on(...).on(...) \$\endgroup\$
    – Bbrk24
    Oct 10, 2022 at 13:48
3
\$\begingroup\$

Apple Shortcuts, 13 actions

This is bad.

Try It Yourself! Copy this link: https://www.icloud.com/shortcuts/86237c5b05454596945efb6b8fdc6cdc and paste into Safari. Only works on iPad and iPhone.

Sorry for large image, I don’t know how to resize it.

Issues:

Because of Apple Shortcut’s limited ability to process strings, input is limited to integers only.

Because of some unknown issue, the length of your integer must be less than 16. This is not because of the loop. I originally set the loop to 200.

Pretty self explanatory, so I don’t feel like adding an explanation.

\$\endgroup\$
3
\$\begingroup\$

Trilangle, 32 31 bytes

'0.<_@<.>i,S)(_<\_//(,.oS(/#..>

I want to say it's possible to do better, but I'm honestly not sure how. Still shorter than Hello, World at least.

Try it on the online interpreter!

Unfolds to the following grid:

       '
      0 .
     < _ @
    < . > i
   , S ) ( _
  < \ _ / / (
 , . o S ( / #
. . > . . . . .

How dense can control flow get before my diagrams are illegible?

The red & green paths push the contents of stdin to the stack, keeping track of the number of characters pushed. The blue path contains the most convoluted "add" instruction ever, and then a decrement-swap-print-pop loop. The yellow path completes the loop while there's still more to be printed, and then the magenta path terminates the program.

Starting on the red path:

  • '0: push a 0 to the stack, representing the number of characters read so far.
  • <: redirect control flow
  • i: get a character from stdin
  • >: branch

If EOF was read, it continues on the blue path; otherwise, it continues on the green path.

The green path increments the counter and closes the loop:

  • _: redirect control flow
  • .: no-op
  • S: swap the two values on top of the stack, so that the counter is on top
  • \: redirect control flow
  • _: no-op when traversed horizontally
  • /: redirect control flow
  • ): increment the top of the stack
  • .: no-op again
  • <: redirect control flow, merging with the red path

On the blue path, the top of the stack is now -1 (representing EOF). The loop later in the program works best if the counter starts one too low -- the branch instruction is "branch if negative", not "branch if zero", so the counter needs to be negative once the output is finished. So, the following instruction sequence is used to transform { ..., n, -1 } to { ..., n - 1 }:

  • ): increment the top of the stack: { ..., n, 0 }
  • _: redirect control flow
  • S: swap the two values on top of the stack: { ..., 0, n }
  • <: redirect control flow
  • _: no-op when traversed horizontally
  • (: decrement the top of the stack: { ..., 0, n - 1 }
  • ): increment the top of the stack: { ..., 0, n }
  • S: swap the two values on top of the stack: { ..., n, 0 }
  • ,: pop the value off the top of the stack: { ..., n }
  • (: decrement the top of the stack: { ..., n - 1 }
  • //: redirect control flow

At this point, it begins to print back out what it's stored (still on the blue path):

  • (: decrement the top of the stack
  • S: swap the two values on top of the stack
  • o: print the character on top of the stack
  • .: another no-op
  • ,: pop the value of the top of the stack
  • .....: more no-ops
  • >: branch

If there are more values to print, the IP takes the yellow path, jumping back into the dec-swap-print-pop loop. Once there are no more values to print, the IP takes the magenta path, performing a lot of useless operations before eventually reaching the @ to end the program.

\$\endgroup\$
2
\$\begingroup\$

Python - 35 chars

import os;print os.read(0,2e9)[::-1]
\$\endgroup\$
9
  • \$\begingroup\$ This is limited to 1e9 characters, though... not technically unlimited. \$\endgroup\$
    – Thomas O
    Jan 30, 2011 at 13:15
  • 2
    \$\begingroup\$ It's not even legal Python, it lacks an argument to os.read(). Should be os.read(0,...) \$\endgroup\$
    – hallvabo
    Jan 30, 2011 at 15:55
  • \$\begingroup\$ @hallvabo, oops you are correct, should be 35 chars.9e9 doesn't work because it is too big to be converted to an int, so 2e9 is as high as it can go. \$\endgroup\$
    – gnibbler
    Jan 30, 2011 at 20:44
  • \$\begingroup\$ what about sys.maxint? \$\endgroup\$
    – Thomas O
    Jan 30, 2011 at 20:46
  • 1
    \$\begingroup\$ @gnibbler: import os,sys is possible. Even os.sys.maxint works for me (might be version/system dependent). \$\endgroup\$
    – hallvabo
    Jan 30, 2011 at 21:16
2
\$\begingroup\$

C++ - 168 chars

#include<algorithm>
#include<iostream>
#include<string>
using namespace std;main(){string m;for(string l;getline(cin,l);)m+=l+"\n";reverse(m.begin(),m.end());cout<<m;}
\$\endgroup\$
1
  • \$\begingroup\$ Can't you #define s string or something like that?or declare m and l at the same time? \$\endgroup\$
    – Behrooz
    Oct 6, 2013 at 20:05
2
\$\begingroup\$

Scala - 60

print(io.Source.fromInputStream(System.in).mkString.reverse)
\$\endgroup\$
2
\$\begingroup\$

Groovy 44 characters

args.reverse().each{print it.reverse()+" "}
\$\endgroup\$
2
\$\begingroup\$

Labyrinth, 10 bytes

,)";@
:".(

Normally, Labyrinth programs are supposed to resemble mazes, but I was able to compress the loops in this one so tightly, that code ended up as a single block (room?). Here is a slightly expanded version which makes it easier to follow the control flow:

,""")""""""";""@
"   "   "   "
:""""   ."""(

, reads one byte at a time from STDIN until it hits EOF and returns -1. The ) increments this value so that we get something positive for each read byte and zero at EOF. The : duplicates each read byte.

Once we hit EOF, the instruction pointer proceeds to the second loop, where it repeatedly discards one value with ; (initially the EOF, later the second copy of each byte), then decrements the next value with ( and prints it with .. Due to that second copy (which is always positive) we know that the IP will take a right-turn at the top and continue in this loop.

After all bytes have been printed the top of the stack is zero again and the IP continues straight ahead to the @ and the program ends.

The seemingly unnecessary duplication of each byte is what allows me to ensure that (even in the tight loops of the golfed version) the IP always takes the correct turn and never crosses from one loop to the other.

A tip of the hat to TheNumberOne and Sp3000 whose own attempts helped a lot in finding this highly compressed solution.

\$\endgroup\$
2
\$\begingroup\$

AppleScript, 81 Bytes

Yeah. I'm amused by the "concision", too.

(display dialog""default answer"")'s text returned's characters's reverse as text

It grabs input from the user from STDIN equivalent (since it's not a terminal based language) and outputs the reverse. Simplez.

\$\endgroup\$
2
\$\begingroup\$

Minkolang 0.10, 6 bytes (non-competitive)

This language was created after this challenge, but not for this challenge.

$or$O.

$o reads in all of the input as characters, r reverses the stack, $O outputs the whole stack as characters, and . stops the program. Try it here.

\$\endgroup\$
2
\$\begingroup\$

Pyke, 1 byte (noncompetitive)

_

Try it here!

\$\endgroup\$
1
  • \$\begingroup\$ Polyglot with Pyth \$\endgroup\$
    – hakr14
    Nov 8, 2022 at 7:16
2
\$\begingroup\$

MarioLANG, 35 31 27 bytes

,)<.-<
+=">="
>[!([!
==#==#

Try it online!

I'm not sure if a MarioLANG interpreter existed prior to this challenge, but the esolangs page has been around since 2009 with information describing the language.

There are 2 main loops here. The first one, consisting of the first 3 columns, loads all the characters into memory (incrememnted by 1 for properly handing eof) The second loop, consisting of the last 3 columns, prints the data on the tape from right to left (along with decrementing the values so they display properly). I did some clever trickery to have these loops directly next to each other.

\$\endgroup\$
2
\$\begingroup\$

Brain-Flak, 15 bytes (non-competing)

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

Try it online!

12 bytes of code, and +3 bytes for the -c flag, which enables input and output in ASCII.

Explanation:

#While the stack is not empty:
{

 #Push the top of the stack onto the alternate stack
 ({}<>)

 #Toggle back to the main stack
 <>

#endwhile
}

#Toggle to the alternate stack, implicitly display
<>
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Just curious, why is -c counted as 3 bytes? \$\endgroup\$ Jan 5, 2017 at 23:35
2
\$\begingroup\$

Java, 165 156 bytes

class R{public static void main(String[]a){System.out.print(new StringBuilder(new java.util.Scanner(System.in).nextLine().replace("\\n","\n")).reverse());}}

Requires you to escape any line breaks in the input, but otherwise it works.

\$\endgroup\$
2
  • \$\begingroup\$ I know it's quite a while since you've answered this question, but you can golf two things: StringBuilder->StringBuffer and you can removed the space at "\\n","\n" (-2 bytes). \$\endgroup\$ Mar 3, 2017 at 10:35
  • \$\begingroup\$ Bringing this back from the dead again! This program cannot handle newlines, which means it isn't a correct submission. The easiest way to fix this would be to have the Scanner read the whole file in one token by setting its delimiter to \A or \z (see Patterns), then invoking next. \$\endgroup\$
    – Jakob
    Aug 15, 2017 at 0:46
2
\$\begingroup\$

Commodore 64/VIC-20 BASIC, 48 BASIC bytes used

Here's a one-liner that will solve this issue:

0 INPUTA$:FORI=1TOLEN(A$):B$=MID$(A$,I,1)+B$:NEXT:PRINTA$":"B$

and here's how it looks on a Commodore 64 (more or less):

Reverse a string in Commodore BASIC

This will work on PETs and the C16/+4 series as well as the C128

\$\endgroup\$
2
\$\begingroup\$

Whitespace, 67 bytes

This program requires a null byte to mark the end of input as Whitespace has no way to detect when stdin is empty. If you're using the TIO link make sure not to delete the last character in the input field (looks like a space) as it's a null byte. If you do you'll need to append a null byte using your browsers console.

   

  	
 
 	
	  
 			
	 
   	
	   
 
	

  
   	
	  	 
 				
  
 


Try it online!

Explanation

(s - space, t - tab, n - newline)

sssn  ; push 0 to use as the starting heap address
nsstn ; label 'read-loop'
sns   ; dup
tnts  ; getchar and store at address n
sns   ; dup
ttt   ; retrieve the character value we just read
ntsn  ; jez 'output-loop' - if it was a null byte switch to output
ssstn ; push 1
tsss  ; add - increment n
nsntn ; jmp 'read-loop'
nssn  ; label 'output-loop'
ssstn ; push 1
tsst  ; sub - decrement n
sns   ; dup
ttt   ; retrieve the character value at address n
tnss  ; putchar - display the character
nsnn  ; jmp 'output-loop'

Whitespace uses a stack and a heap for data storage. As I/O commands write to the heap naturally we store the string on the heap and keep the stack for our counter.

This program reads characters one at a time and stores them in order starting from heap address 0 counting up. Once the program reads a null byte it starts displaying characters starting from the previous heap address counting down. For the input hello\0 this populates the heap as [#0:h,#1:e,#2:l,#3:l,#4:o,#5:\0] then outputs the characters at addresses #4,#3,#2,#1,#0 and we end up with olleh.

\$\endgroup\$
0
2
\$\begingroup\$

Excel VBA, 18 + 1 = 19 Bytes

Anonymous VBE function that takes input from range [A1] and outputs it reversed to the VBE immediate window

Code:

?StrReverse([A1])

+1 for ' before input in cell A1 (allows for handling strings that begin with '=')

\$\endgroup\$
2
  • \$\begingroup\$ Can you omit last right parenthesis? \$\endgroup\$
    – user100411
    Apr 8, 2021 at 11:10
  • 1
    \$\begingroup\$ @tailsparkrabbitear - unfortunately not, VBA requires explicit closing of parens \$\endgroup\$ Apr 8, 2021 at 17:52
2
\$\begingroup\$

Brachylog, 1 bytes

(maybe noncompeting?)

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Common Lisp, 67 bytes

(do((a))((push(or(read-char()())(return(coerce a'string)))a)))

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Julia 0.6, 33 bytes

print(reverse(readstring(STDIN)))

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Japt, 1 byte

w

Try it online!

\$\endgroup\$
2
\$\begingroup\$

R, 41 bytes

cat(intToUtf8(rev(utf8ToInt(scan(,"")))))

Try it online!

Alternate "classic" version working directly with characters:

R, 53 bytes

for(i in rev(el(strsplit(scan(,""),split=""))))cat(i)

Try it online!

Because every question deserves at least one answer in R. Even string questions...

\$\endgroup\$
2
\$\begingroup\$

CJam, 19

1q]e_{_1#0=}{)\}w;;

This is the first golfing language I've tried to learn, and I just started learning it. It's pretty crazy, but it works in the online interpreter. [Try it here][1].

Explanation (It's very hard for me to explain it, maybe someone can help):

1q]        #e  puts a 1 and the text input into an array
e_         #e  flatten the array
{_1#0=}    #e  check if if the 1 is at the beginning of our array. If true, we keep looping. The trick is once the array is destroyed, we are applying the # operator on 1 not the array, in which case it is a power operator, so it's (1)^(1), which is 1, not 0. Yeah it's ridiculous.
{)\}w      #e  in the body of the while loop we pop the last element off of the array and put it onto the stack. 
;;         #e  then we need to get rid of the 1 so we pop the top element off the stack. I'm not sure why we need to do this twice.
 

[1]: http://cjam.aditsu.net/#code=1q%5De_%7B_1%230%3D%7D%7B)%5C%7Dw%3B%3B&input=High%0ABye%09Cool%0ATry

\$\endgroup\$
2
  • 1
    \$\begingroup\$ qW% is a bit shorter. :) \$\endgroup\$
    – Dennis
    Nov 3, 2015 at 6:03
  • \$\begingroup\$ Oh, I see: take every -1st. Very clever, thank you! \$\endgroup\$
    – geokavel
    Nov 3, 2015 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.