g | x | w | all
Bytes Lang Time Link
004Uiua241123T192258ZErikDaPa
nan241123T194023Zamir hom
025AWK241122T203539Zxrs
006Juby241122T145908ZJordan
003Pyth150622T174839Zcmxu
nanmIRC 4.45 35 Bytes160604T102347ZO S
034Oracle SQL 11.2160603T142656ZJeto
033Python 3160603T142045Zm654
026Python 2160603T135810ZErik the
003MATL160124T051407ZLuis Men
002Burlesque151022T170317Zmroman
014Mathematica151022T165312ZMartin E
nan151022T164455Zletsch32
054TIBASIC140408T155156ZTimtech
031ES6 Javascript150704T143121ZAfonso M
058C#150704T044404ZCooler R
023Julia150703T215743ZM L
3128TIBASIC150622T233514Zuser3932
025POWERSHELL150623T065139Zblabb
020rs150623T020211Zkirbyfan
003K150622T181503ZJohnE
011Brainfuck140702T130348Zrpax
035JavaScript ES6140227T055758ZEliseo D
029Rebol140227T222754Zdraegtun
nan110831T192407ZEd Staub
032Groovy131202T091137ZCarlos G
023Haskell131201T004904ZThom Wig
nan130110T193148ZPjot
044Game Maker Language131130T161155ZTimtech
nan131130T153711ZFireFly
nan110611T105522ZKiril Ki
060Common Lisp121230T215645ZChris Zi
nan121229T162557ZTwiN
035R121202T132244ZAri B. F
nan121201T074859Ztusharma
003Befunge121201T022037Zdaniero
014Ruby110611T124556Zbodaciou
009PHP110611T124215Zpowtac
037PHP120501T195550Zl0n3sh4r
003APL120501T175353Zmarinus
026ruby120312T091243Zjsvnm
004k3120311T215419ZAdam Sch
020in Q120307T173819Zsinedcm
nan120308T190446Zmarinus
005Golfscript110830T191351ZPeter Ta
001HTML 7 chars110819T150917ZGriffin
075Scheme110612T165945Zkba
042Clojure111129T040501ZOmar
011Perl111126T142948ZZaid
nan111124T121553ZArmand
019Perl110819T190832ZDynamic
006k4110830T222500Zfrank
nan110831T152045ZKumsal O
nanThis one ACTUALLY takes an input110830T184251ZExelian
017Vim110819T084245ZEric For
nan110621T204147ZAlex
nan110616T190116ZJAB
006Perl110613T034710ZMing-Tan
nan110611T114913ZVader
033Scala 33 Chars110612T112754ZLalith
nan110611T144147ZDan Dipl
2824Haskell110611T113250Zhammar
006J110611T123503ZMPelleti
nan110611T105441ZRobG
nan110611T111638ZVictor
nanthis is AS3 code110611T105848Zpico.cre
nanIt is possible to convert a number a string110611T110020Ztaskinoo

Uiua, 4 bytes

⍜°⋕⇌

Explanation:

⍜°⋕⇌
⍜    => under (do 1st func, then the 2nd, then undo the 1st)
 °⋕  => number to string (1st func), undo func -> string back to number
   ⇌ => reverse (2nd func)

Try this online!

Python

def ans(n):
    L = str(n)
    return(int(L[::-1]))

AWK, 25 bytes

{for(i=NF;i;i--)printf$i}
awk -F "" '{for(i=NF;i;i--)printf$i}' <<< 123

J-uby, 6 bytes

S|:~|Z

S converts to string, :~ reverses, Z converts to integer.

Attempt This Online!

Pyth (3 chars)

Try it here

v_z

mIRC 4.45 (35 Bytes)

$regsubex(12,/(.)/g,$mid(\A,-\n,1))

Oracle SQL 11.2, 35 34 bytes

SELECT 0+REVERSE(:1||'')FROM DUAL;

Python 3, 33 bytes

I decided to make a function instead of hardcoding it.

def r(n):print(int(str(n)[::-1]))

The code is pretty self-explanatory.

Usage: r(12345)

Python 2, 26 bytes

print int(`input()`[::-1])

MATL, 3 bytes (non-competing)

VPU

This uses release 10.1.0 of the language/compiler, which is the current version at the time of writing.

Try it online!

Explanation

V   % implicitly input a number and convert to string
P   % flip
U   % convert to number and implicitly display

Burlesque, 2 bytes

Certain built-ins treat numbers as list of digits. The reverse built-in for example treats integers as a list of digits and thus reverses integers.

blsq ) 76543<-
34567

(For characters <- switches case).

Mathematica, 14 bytes

IntegerReverse

This is not competing, because this function was only added in last week's 10.3 release, but for completeness I thought I'd add the only ever (I think?) built-in for this task.

C++:

int reverse(int number, int number1, int number2){std::vector<int> v; v.push_back(number); v.push_back(number1); v.push_back(number2); std::cout << v[2] << v[1] << v[0]; return 0;}

TI-BASIC, 58 54

Input N:0:While N>0:Ans+E3fpart(N,10:N/10→N:End:Ans

Usage

prgmREVERSE
?598028
          820895
            Done

ES6 Javascript, 31 bytes

x=>[...x+''].reverse().join('')

C# - 58

I think we need more C#

int.Parse(string.Concat(Enumerable.Reverse(x.ToString())))

Julia, 23

r(x)=int(reverse("$x"))

$ interpolates an argument (or the result of a function) into a string, denoted by the double quotes. int() automatically deletes leading zeroes.

Example:

julia> x=1234567890;r(x)
987654321

or

julia> r(1234567890)
987654321

TI-BASIC, 35 32 31 (or 28) bytes

Takes input from the calculator's answer variable, which is whatever was last evaluated (like _ in the interactive python shell).

fPart(.1int(Ans10^(seq(A,A,~int(log(Ans+.5)),not(Ans
sum(Ans10^(cumSum(1 or Ans

10^( is 2NDLOG and ~ is ( - ), next to ENTER. Everything else can be found in the 2ND0 catalog.


If the program doesn't have to handle the possibility of 0 as input, it can be reduced to 28 bytes by changing ~int(log(Ans+.5)),not(Ans to ~int(log(Ans)),0.
Credit goes partially to Thomas Kwa for helping to golf this.

POWERSHELL, 25

-join(Read-Host)[-1..-9]

a longer version to take arbitrary input , 36

-join($a=Read-Host)[-1..-$a.length]

usage

PS C:\> -join(Read-Host)[-1..-9]
123456789
987654321
PS C:\>

rs, 20 bytes

#
+#(.*)(.)/\2#\1
#/

Technically, this doesn't count (rs was created earlier this year), but I didn't see any other regex-based answers, and I thought this was neat.

Live demo.

Explanation:

#

Insert a pound character at the beginning of the string. This is used as a marker.

+#(.*)(.)/\2#\1

Continuously prepend the last character of the main string to the area before the marker until there are no characters left.

#/

Remove the marker.

K, 3 bytes:

.|$

Evaluate (.) the reverse (|) of casting to a string ($).

Usage example:

  .|$76543
34567

Brainfuck, 11

>,[>,]<[.<]

JavaScript (ES6) 35

a=b=>b.split("").reverse().join("")

Rebol, 29

f: func[n][do reverse mold n]

Usage example in Rebol console:

>> f 76543
== 34567

If you only wanted this to work on integer input then....

f: func [n [integer!]] [do reverse mold n]

Java

""+new StringBuilder(""+i).reverse();

Groovy 32

def r(n){print ((n+"").reverse())}

Haskell, 61,23

Using the string reversing technique. digitToInt is available from the Data.Char library, and of course this code would be shorter if we'd be able to assume if Data.Char already was available.

-- original version 61 chars
foldl1((+).(*)10).map(Data.Char.digitToInt)$reverse$show 1234

--bonus foldonly version, 67 chars
foldl1((+).(*)10).foldl(flip((:).Data.Char.digitToInt))[]$show 1234

--FireFly's suggestion: 23 chars. Note that read's return type is `a`
-- so you might want to tack on a +1 on ghci etc so `Int` can be derived.
read.reverse.show$1234

BaCon

PRINT REVERSE$(STR$(76543))

Replace 76543 with any number.

Game Maker Language, 44

Replace 12345 with whatever number or variable you want:

n=12345while(n>0){r=r*10+(n mod 10)n div 10}

If you want to prompt for user input, use this 56 character long code instead:

n=get_string('','')while(n>0){r=r*10+(n mod 10)n div 10}

In both pieces of code, the reverse number is stored in r

Language-independent/mathematics

Inspired by Kiril Kirov's answer above. I got curious about the mathematical properties of reversing a number, so I decided to investigate a bit.

Turns out if you plot the difference n - rev(n) for natural numbers n in some base r, you get patterns like this ((n - rev(n)) / (r - 1), for r=10, wrapped at r columns, red denotes negative number):

table of differences

This sequence could be generated as such (pseudocode):

for i=1 to r:
  output 0

for m=0, 1, …
  for k=1 to (r-1):
    for d=1 to r^m:
      for i=0 to (r-1):
        output (r-1) * (r+1)^m * (k - i)

If you store these values in a list/array, then n - arr[n] would get you the reversed form of n. Now, to "mathematically golf" this, we'd ideally want a closed-form expression that gives us the n:th value in the sequence, so that we could have a closed-form expression for solving the entire task. Unfortunately, I haven't been able to find such an expression... but it looks like it should be possible. :(

So yeah, not so much a code-golf as a mathematical curiosity, but if there is a closed-form expression of the above sequence it might actually be useful in proper PL golf submissions.

Universal (language agnostic/independent)

If you want to use only numbers (avoid converting the number to string) and don't want to use some specific library (to be universal for any language):

x = 76543 # or whatever is your number
y = 0
while x > 0:
    y *= 10
    y += ( x %10 )
    x /= 10 # int division 

This is python, but it could be done in any language, because it's just a math method.

Common Lisp - 60 chars

(first(list(parse-integer(reverse(write-to-string '4279)))))

will get you 9724.

Kinda late but

APL, 3

⍎⌽⍞

If you insists on a function

⍎∘⌽∘⍕

R (35 characters)

> cat(rev(strsplit("12345","")[[1]]))
5 4 3 2 1

With help from my friends in R chat.

In shell scripting :

  echo "your number"|rev

Hope this was useful :)

Befunge (3 characters)

Complete runnable program:

N.@

Where N is your number. Rules say "accept a single integer valued argument"; In Befunge you can only enter integers from 0 to 9.

Ruby (14)

x = 13456
x.to_s.reverse

PHP, 9 chars

(int)strrev(123);

To do it short where N is a constant:

strrev(N)

PHP, 37

<?function f($n){return strrev($n);}

C, 44

x;m(n){for(;n;x=x*10+n%10,n/=10);return x;}

APL (3)

⍎⌽⍕

Usage:

⍎⌽⍕12345 => 54321

ruby (26)

The existing ruby answer wasn't a function/lambda, so here goes:

f=->i{i.to_s.reverse.to_i}

k3, 4 chars

0$|$

0$|$76543 \-> gives 34567

See also the K4 solution here. The only difference (saving two chars) is that 0$ converts to int.

in Q (20 characters)

f:{"I"$reverse -3!x}

Sample Usage:

q)f 89478237
73287498

Use the k version of reverse (wrapped in parentheses) to make it shorter

{"I"$(|:) -3!x}

also just define it as a lambda to take 2 chars off for a total of 15

Bash (15)

read a;rev<<<$a

As a number of other entries do, '01234' becomes '43210' and '2340' becomes '0432'; i.e. in Python terms it does print reverse(raw_input()). If behaviour like print int(reverse(str(int(raw_input())))) is expected, it is a bit longer:

Takes care of trailing zeroes (36)

read a;sed s.^0*..\;s.0*$..<<<$a|rev

Golfscript, 5 chars

`-1%~

This takes an argument on the stack and leaves the result on the stack. I'm exploiting the "subprogram" option in the spec: if you insist on a function, that's four chars more leaving it on the stack:

{`-1%~}:r

HTML 21 7 chars (1 char if I'm cheeky...)

&#8238;n

replace n with your number

Scheme, 75 characters

(string->number(list->string(reverse(string->list(number->string 76543)))))

Clojure (42 chars)

#(->> % str reverse(apply str)read-string)

Example usage:

(#(->> % str reverse(apply str)read-string) 98321)

returns 12389

Perl, 11 chars

The p flag is needed for this to work, included in the count.

Usage:

$ echo 76543 | perl -pE '$_=reverse'

Groovy

r={"$it".reverse() as BigDecimal}

assert r(1234) == 4321
assert r(345678987654567898765) == 567898765456789876543
assert r(345346457.24654654) == 45645642.754643543

Perl (19 chars)

Simple:

$x=reverse (98765);

k4 - 6 characters

"I"$|$

Examples:

  "I"$|$76543
34567
  "I"$|$98765
56789

Explanation from right to left: ("I"$ = cast to integer)(| = reverse)($ = convert to string)

Actionscript

43 characters. num as the parameter to the function:

num.toString().split('').reverse().join('')

This one ACTUALLY takes an input, unlike some of the rest:

print`input()`[::-1]

Python btw.

Vim

17 chars

:se ri<CR>C<C-R>"

Lua

Numbers and strings are interchangeable, so this is trivial

string.reverse(12345)

Python 3+

Function form: 28 characters

r=lambda i:int(str(i)[::-1])

(Sub)program form: 25 characters

print(input()[::-1])

I consider some of the other Python examples to be cheating, or at least cheap, due to using hardcoded input and/or not fully satisfying the requirements.

Perl 6

+$n.flip

or:

$n.flip

for dynamically typed code.

Numbers got string methods due to language design.

Python

int(str(76543)[::-1])

EDIT:

Shorter solution as suggested by @gnibbler:

int(`76543`[::-1])

or, if above is unclear:

x=76543
int(`x`[::-1])

Scala - 33 Chars

def r(a:Int)=(a+"").reverse.toInt

C#

int reversed = Convert.ToInt32(String.Join<char>(null, 76543.ToString().Reverse()));

Haskell, 28 24 characters

f=read.reverse.show.(+0)

J - 6 characters + variable

".|.":y

Where y is your value.

Depends on what you mean by short (javascript):

alert(String(123).split('').reverse().join('')),

You could do the following in Java. Note that this converts to String and back and is not a mathematical solution.

public class test {
    public static int reverseInt(int i) {
        return Integer.valueOf((new StringBuffer(String.valueOf(i))).reverse().toString());
    }

    public static void main(String[] args) {
        int i = 1234;
        System.out.println("reverse("+i+") -> " + reverseInt(i));
    }
}

this is AS3 code, so you may need to make slight changes

function reverseData ( inData:String ):* {
    var ar1 = inData.split(''); //Takes string value, split each digit into an array

    var ar2 = ar1.reverse(); //Inverses the array direction 
    /* //OR (if not supported) [not AS3]
    var ar2 = new Array();
    for( var i:int = (ar1.length - 1); i > 0; i++ ) {
        ar2.push( ar1[i] );
    }
    */

    var result = ar2.join();
    return result;
}

It should work for a string equavalent (that should be easy to typecast)

For a javascript example...

function flip( inData ) {
    return ( parseInt( (inData + '').split('').reverse().join('') ) );
}

alert( flip(123) );

It is possible to convert a number a string, then reverse the string and then convert that string back to number. This kind of feature is probably available in all language. If you are looking for a more mathematical method then this might help:

int n = 76543;
int r = 0;

while (n > 0) {
    r *= 10;
    r += n % 10;
    n /= 10;
}