Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Reverse an ASCII string

+11
−0

Your goal is to reverse an ascii string. Given a (optionally newline or null terminated) input, output your input in reverse order, optionally followed by a newline. Terminate afterward. Function answers will not be given a newline, and are not expected to output one unless they print the answer to console.

Examples

Assume all inputs are followed by a newline, and are all standard ASCII encoded.

abcdef -> fedcba
Hello, World! -> !dlroW ,olleH
racecar -> racecar

Example program

function solution(x) {
    return x.split("").reverse().join("");
}

Further clarifications

  • No, you don't have to handle nulls correctly.
  • Nor empty inputs.
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (7 comments)

33 answers

+2
−0

Lua, 32 bytes

print(string.reverse(io.read()))

Try it online!

Noice built-in.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+2
−0

Befunge-98, 45 39 37 33 29 21 bytes

v:~<
>a-|
>v$<
,:
^_@

Try it online!

This answer probably sucks :P

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

General comments (2 comments)
+1
−0

Python, 16 bytes

lambda s:s[::-1]

Attempt This Online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

shortC, 24 bytes

f(C*s){*s&&f(s+1)^P*s);}

Try it online!

A shortC conversion of @Sisyphus's C (gcc) implementation.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

J, 2 bytes

|.

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Rockstar, 67 bytes

listen to S
split S
O's""
while S
roll S into C
let O be C+O

say O

Try it here (Code will need to be pasted in)

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

AWK, 48 bytes

ORS="";{l=split($0,d,"");for(;l>0;)print d[l--]}

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

Standard ML, 23 bytes

implode o rev o explode
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

Java (JDK), 88 83 bytes

static void f(String s){for(int i=s.length();i>0;System.out.print(s.charAt(--i)));}

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

R + magrittr, 31 bytes

.%>%utf8ToInt%>%rev%>%intToUtf8
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

SOS, 76 bytes

+>+>?<+>?<+>?<+>?<+>?<+>?<+>?<+>?<<)<<-(>{>!<{>!<{>!<{>!<{>!<{>!<{>!<{>!<<-)
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

Brainfuck, 10 Bytes

,[>,]<[.<]

Requires EOF to be 0.

Try it online!

,[>,]<[.<]

,           # Read character
 [  ]       # loop as long as current cell is not 0 (EOF)
  >,        # read and fill the tape to the right with the read characters
     <      # go back to the last valid character, i.e. one before EOF
      [  ]  # loop till current cell is 0 (i.e. cell pointer is before the first read character
       .<   # output character and move left
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

R, 32 bytes

\(s)intToUtf8(rev(utf8ToInt(s)))

Attempt This Online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »