| Bytes | Lang | Time | Link |
|---|---|---|---|
| 040 | TIBASIC TI84 Plus CE Python | 250911T163500Z | madeforl |
| 038 | AWK | 250910T163307Z | xrs |
| 036 | SNOBOL4 CSNOBOL4 | 230228T152907Z | Giuseppe |
| 007 | GolfScript | 230228T152715Z | emirps |
| 011 | Juby | 221204T170704Z | Jordan |
| 004 | Pip | 221203T080615Z | Aiden Ch |
| 041 | Leaf Lang | 220909T173332Z | Breadlea |
| 089 | CellTail | 220908T120300Z | mousetai |
| 028 | Julia | 220908T110806Z | amelies |
| 047 | Prolog SWI | 220827T164105Z | naffetS |
| nan | Fig | 220907T185807Z | Seggan |
| 032 | Julia | 220830T061910Z | Czylabso |
| 008 | CJam | 220830T105611Z | Chilling |
| 028 | brev | 220831T081618Z | Sandra |
| 002 | MathGolf | 220830T071954Z | Kevin Cr |
| 097 | Desmos | 220829T192404Z | thejonym |
| 072 | JavaScript | 220827T105923Z | Leaf |
| 002 | Vyxal | 220827T045522Z | tybocopp |
| 005 | Burlesque | 200207T005305Z | DeathInc |
| 003 | Keg | 200206T074057Z | lyxal |
| 061 | Pepe | 190513T050130Z | u-ndefin |
| 010 | Runic Enchantments | 190513T013917Z | Draco18s |
| 002 | Ohm v2 | 171010T021535Z | Nick Cli |
| 033 | ><> | 190308T113619Z | Emigna |
| 016 | APLNARS | 190308T100321Z | user5898 |
| 052 | Java 8 | 190308T003840Z | Benjamin |
| 005 | APL Dyalog Unicode | 171117T130932Z | J. Sall& |
| 021 | Gol><> | 180222T094919Z | Unihedro |
| 050 | Java 8 | 171010T073039Z | Kevin Cr |
| 024 | Ruby | 171010T045846Z | Yytsi |
| 005 | MATL | 180220T201955Z | B. Mehta |
| 003 | Pyt | 180220T200049Z | qqq |
| 004 | Jelly | 180125T233418Z | ellie |
| 022 | REXX | 171121T152005Z | idrougge |
| 005 | Implicit | 171012T160128Z | MD XF |
| 039 | ><> | 171117T234803Z | Bolce Bu |
| 022 | Excel VBA | 171010T203754Z | Taylor R |
| 014 | Add++ | 171119T173613Z | caird co |
| 042 | Lua | 171117T224123Z | MCAdvent |
| 008 | Aceto | 171116T203224Z | qqq |
| 012 | QBIC | 171014T093030Z | steenber |
| 1215 | Batch | 171010T051154Z | Ephellon |
| 231 | PHP | 171012T160836Z | Titus |
| 105 | Batch | 171011T221930Z | Slapparo |
| 055 | C# .NET | 171010T082304Z | Kevin Cr |
| 031 | PowerShell | 171011T142913Z | colsw |
| 018 | Bash + GNU utilities | 171011T004646Z | Digital |
| 054 | Pyth | 171010T214046Z | chromati |
| 058 | R | 171010T200420Z | Giuseppe |
| 037 | Swift 4 | 171010T194353Z | Mr. Xcod |
| 048 | bash | 171010T081037Z | Nahuel F |
| 034 | Tcl | 171010T193800Z | sergiol |
| 054 | SAS | 171010T193615Z | J_Lard |
| 064 | LISP | 171010T082649Z | Aesthete |
| 025 | Python 2 | 171010T181507Z | Jonathan |
| nan | 171010T165431Z | Brad Gil | |
| 023 | Haskell | 171010T045946Z | Wheat Wi |
| 003 | Jelly | 171010T025415Z | JungHwan |
| 049 | C gcc | 171010T080211Z | Leaky Nu |
| 007 | J | 171010T074925Z | cole |
| 087 | Batch | 171010T074817Z | Neil |
| 009 | Alice | 171010T074811Z | Martin E |
| 031 | MATLAB/Octave | 171010T073728Z | Tom Carp |
| 002 | Japt | 171010T072541Z | Shaggy |
| 006 | Recursiva | 171010T071431Z | 0xffcour |
| 028 | JavaScript SpiderMonkey | 171010T022400Z | Ephellon |
| 013 | LOGO | 171010T064611Z | user2027 |
| 006 | Husk | 171010T061945Z | Laikoni |
| 6018 | C# .NET Core | 171010T062116Z | Ian H. |
| 044 | CasioBasic fxCP400 | 171010T061321Z | numberma |
| 028 | Python 3 | 171010T032822Z | LyricLy |
| 066 | Octave | 171010T060123Z | Michthan |
| 002 | 05AB1E | 171010T042725Z | Mr. Xcod |
| 004 | Pyth | 171010T042008Z | Mr. Xcod |
| 007 | Ly | 171010T035207Z | LyricLy |
| 008 | cQuents 0 | 171010T034512Z | Stephen |
| 019 | Mathematica | 171010T023627Z | JungHwan |
| 012 | ARBLE | 171010T022231Z | ATaco |
| nan | Perl 5 | 171010T022854Z | Xcali |
| 006 | RProgN 2 | 171010T022119Z | ATaco |
TI-BASIC (TI-84 Plus CE Python), 40 bytes
Input N
int(log(N
Nsum(seq(₁₀^(E),E,Ans,0,-1)int(10fPart(N₁₀^(seq(-X-1,X,0,Ans
GolfScript, 7 bytes
.`-1%~*
Link includes test cases
Explanation
code # explanation | stack
.`-1%~* # function which takes an input integer n | n
. # duplicate n | n n
` # stringify | n str(n)
-1% # reverse | n reverse(str(n))
~ # eval | n reverse(n)
* # multiply | n*reverse(n)
J-uby, 11 bytes
:*%(S|:~|Z)
Explanation
:* % (S | :~ | Z)
S | :~ | Z # Convert input to string, reverse, then convert to int
:* % ( ) # Multiply by input
```
Leaf Lang, 41 bytes
Note: The interpreter does not have a stable release. If I introduce a breaking change I will update this post.
import"string.lf"argv:o o reverse o*print
Explained:
import "string.lf" - import stdlib's string.lf
argv - push all of argv onto stack
:o - set o to top value from stack (pops top)
o - push o to top of stack
reverse - reverse the string
o - push o to top of stack
* - leaf lang will implicitly convert strings to numbers when applicable
print - print top value of stack with no newline
Ungolfed:
import "string.lf"
argv : num
num reverse num *
print
CellTail, 89 bytes
1,_,_:1,N,N;N,(a,0,c),_:N,a*c,1;N,(a,b,c),_:N,(a,b/10,c*10+b%10),1;N,a&N..,N:N,(a,a,0),1;
CellTail has no way to turn a number into a string so we have to use modulus and integer division. Uses the cell to the right to provide recursion resistance.
Fig, \$2\log_{256}(96)\approx\$ 1.646 bytes
*$
See the README to see how to run this
*$ # Full program
* # Multiply
$ # The reversed number
# By the implicit input
Julia, 33 32 bytes
~n=foldl((x,y)->10x+y,digits(n))n
- 1 more byte saved by @MarcMush:
a^b=10a+b
~n=foldl(^,digits(n))n
brev, 28 bytes
(fn(*((as-list reverse)x)x))
Crashes on negative
MathGolf, 2 bytes
x*
Explanation:
x # Reverse the (implicit) input-integer
* # Multiply it by the (implicit) input-integer
# (after which the entire stack is output implicitly as result)
Desmos, 97 bytes,
f=\left\{x>0:floor(log(x))+1,0\right\}
g(x)=x∑_{n=0}^f10^{f-n}floor(mod(\frac{x}{10^{n-1}},10))
Not sure if this is legal as a Desmos answer, uses the fact that variables can be defined in terms of x, but functions of x can use those variables as functions? I'm not sure what actually is happening, but it seems to be... working. If I'm not allowed to use that, change f= to f(x)= for +3 bytes
Only works for nonnegative integers, which I think is fine since OP doesn't include any test cases for them, and they're not well defined for this problem (what is -1 backwards? 1-? That's not a number IMO). If I'm allowed to assume positive integers, the first line can become
f=floor(log(x))+1
for -21 bytes. Very nice, but the challenge says "integers", so it's iffy.
In general though, I know this is further golfable but I tried some of the Desmos tips and I must be doing something wrong because they weren't working. I'll come back and golf this eventually.
Code breakdown:
f=\left\{x>0:floor(log(x))+1,0\right\} definition of... function(?) f
f= define f as
x>0: if x is positive
floor(log(x))+1 length(x)
,0 else 0
i dont remember why but this works to make g(0)=0
g(x)=x∑_{n=0}^f10^{f-n}floor(mod(\frac{x}{10^{n-1}},10)) definition of main function
g(x)= define g(x) as
x x times
∑ the sum of
_{n=0}^f for each n from 0 to f(x)
10^{f-n} 10^(f-n) times
floor(mod(\frac{x}{10^{n-1}},10)) the nth digit from the right of x
essentially: sum of
(nth digit of x)
multiplied by
(place value of
(length(x)-n)th digit of x
aka: reverse(x)
JavaScript, 72 bytes
Doesn't use strings. At all.
-10 by steffan
n=>(a=[],r=n=>(n>9&&r(n/10|0),a=[n%10,...a]))(n).reduce((a,v)=>a*10+v)*n
Runic Enchantments, 11 10 bytes
i:0qr͍n*@
Takes input, duplicates it, coerces one copy to a string, reverses it, coerces it back to a numerical value, multiplies, and outputs the result.
0q performs the coercion to a string by concatenating a zero onto the end. There is no explicit ToString() operator, so this is the shortest method in this specific case where the 0 swapped to the beginning doesn't alter the resulting numerical value. Thanks to ASCII-only for this -1 byte.
Ohm v2, 2 bytes
œΠ
Explanation:
œΠ Main wire, arguments: n
œ Pushes [n, n.reverse]
Π Multiplies that array together
Implicit output
APL(NARS), 8 char, 16 bytes
{⍵×⍎⌽⍕⍵}
test:
f←{⍵×⍎⌽⍕⍵}
f 23
736
23×32
736
f 11
121
Java 8, 52 bytes
n->new Long(new StringBuilder(n+"").reverse()+"")*n;
Try it online
This will give every linter/IDE/compiler a stroke, but hey, it works
APL (Dyalog Unicode), 9 5 bytes
⍎×⍎∘⌽
Tacit prefix function. Takes input as a string of digits.
Thanks to Adám for 4 bytes.
How it works:
⍎×⍎∘⌽ ⍝ Anonymous, tacit function.
⌽ ⍝ Reverse the input
⍎∘ ⍝ Convert to number
× ⍝ and multiply
⍎ ⍝ by input converted to number
Gol><>, 21 bytes
I:WaSD$|r}l3-Fa*+|+*h
An example > A million words
I :D WaSD$D| Dr}l3-D Fa*+D| D+*h
^659
[659 659]
[659 9 65]
[659 9 5 6]
[659 9 5 6 0]
[659 9 5 6 0]
[659 0 6 5 9 2] <- 2 = operations to do
[659 0 6 95]
[659 0 956]
[659 0 956]
Alternate
I:WaSD$|~r}l2-Fa*+|*h
I:&WaSD$|~rlMFa*+|&*h
Java 8, 50 bytes
n->n*new Long(new StringBuffer(n+"").reverse()+"")
Pretty straightforward.
n->: Lambda-function with 64bit-number as inputn+"": Convert the input-number to Stringnew StringBuffer(...): Convert this String to aStringBuffer.reverse(): Reverse it...+"": Convert theStringBufferback to Stringnew Long(...): Convert this String back to a 64bit-numbern*...: Multiply it with the original input, and return it
Arithmetic approach would be slightly longer (55 bytes):
n->{int i=n,j=0;for(;i>0;i/=10)j=j*10+i%10;return j*n;}
Explanation can be found in my C# .NET port.
Ruby, 25 24 bytes
->n{n*eval(n.digits*'')}
Integer#digits returns a list of reversed digits, so further reversing is not necessary.
Thanks to @benj2240 for golfing a byte!
MATL, 5 bytes
VPUG*
Explanation: V converts to string, P flips, U converts back to numeric, G copies the original input again, and * multiplies them together.
REXX, 22 bytes
arg n
say n*reverse(n)
Implicit, 5 bytes
:ì\ì*
« implicit integer input »;
: « duplicate »;
ì « convert to string »;
\ « reverse »;
ì « back to int »;
* « multiply »;
« implicit integer output »;
><>, 41 39 Bytes
:&>:a%:}-\
/~\?)0:,a/
>l1-?\&*n;
\ +*a/
How it works:
:&
Assume input has been pushed to the stack (https://codegolf.meta.stackexchange.com/a/8493/76025). Duplicate it and store a copy in the register.
>:a%:}-\
\?)0:,a/
Converts this to its individual digits, leaving them on the stack.
/~
>l1-?\
\ +*a/
The top value will always be a zero due to the number-to-digit conversion process; drop it from the stack. Now, while the length is >1, multiply the first item by ten and add it to the item below it. This results in the number reversed.
&*n;
Multiply the original number by the reverse, print the answer, and stop.
Excel VBA, 27 22 Bytes
Anonymous VBE Immediate window function that takes input from [A1] and outputs to the VBE immediate window
?[A1]*StrReverse([A1])
Add++, 14 bytes
D,f,@,EDE@EdA*
How it works
With example input of 12
D,f,@, - Create a monadic function, f
ED - To digits; STACK = [[1 2]]
E@ - Reverse; STACK = [[2 1]]
Ed - From digits; STACK = [21]
A - Argument; STACK = [21 12]
* - Product; STACK = [252]
Aceto, 8 bytes
rd~isi*p
r reads input d duplicates it ~ reverses the top value i convertes it to an integer s swaps the two top values i convertes the other value to an integer * multiplies the top two p prints the result
QBIC, 12 bytes
_F!:$|?a*!A!
Explanation
: Get the input number from the cmd line and assign to 'a'
! $ Cast it to string
_F | and flip[ that, assigning it into A$
?a* PRINT 'a' times
!A! A$ cast back to int
Batch, 150 125 121 bytes (+ 5 bytes? cmd/q)
set l=%1
set n=0
set r=
:L
call set t=%%l:~%n%,1%%%
set/an+=1
if [%t%] neq [] set r=%t%%r%&goto L
set/ar=%r%*%l%
echo %r%
Saved 25 bytes thanks to user202729!
Saved 4 bytes thanks to Matheus Avellar!
PHP, 23+1 bytes
<?=$argn*strrev($argn);
Save to file and run as pipe with -nF.
Batch, 105 bytes
@set c=
@set a=%1
:J
@set c=%c%%a:~-1%
@set a=%a:~0,-1%
@if NOT "%a%" == "" goto J
@set/ac=%1*%c%
The reverse is performed in a loop which appends the last character @set c=%c%%a:~-1% from the input to c, and then removes the last character from the input string @set a=%a:~0,-1% - rinse and repeat until there are no characters left on the input string. A quick multiplication @set/ac=%1*%c% and done.
C# .NET, 55 bytes
n=>{int i=n,j=0;for(;i>0;i/=10)j=j*10+i%10;return n*j;}
Explanation:
n=>{ // Method with integer as both parameter and return-type
int i=n, // Integer `i` (starting at the input)
j=0; // Integer `j` (starting at 0)
for(;i>0; // Loop as long as `i` is not 0
i/=10) // After every iteration: Remove the last digit of `i`
j=j*10 // Add a trailing zero to `j`,
+i%10; // and then sum this new `j` with the last digit of `i`
// End of loop (implicit / single-line body)
return n*j; // Return the input multiplied with `j`
} // End of method
PowerShell, 31 Bytes
param($a)$a*-join("$a"[-1..-9])
Powershell is more than happy to multiply a number by a valid numerical string which is nice.
Pyth, 5 4 bytes
*v_`
Explanation:
*v_`QQ : accepts a number as input
`Q : represent input as string
_ : reverses string
v : evaluates the string as a number again
* Q : multiply by the input
: implicit output
(remove Q's as Pyth adds them for you)
R, 58 bytes
cat((n=scan())*sum(n%/%10^(d=1:nchar(n)-1)%%10*10^rev(d)))
reads from stdin, writes to stdout. n%/%10^(d=1:nchar(n)-1)%%10 is how we get the digits, and reversing them is as simple as taking that vector, multiplying by 10^rev(d), and summing.
R + stringi, 47 bytes
cat(strtoi(stringi::stri_reverse(n<-scan()))*n)
stringi (not stringr) has a stri_reverse command.
bash, 52 48 bytes
for((i=n=$1;r=r*10+i%10*n,i/=10;));{ :;};echo $r
SAS, 54 bytes
%macro f(n);%put%eval(&n*%sysfunc(reverse(&n)));%mend;
LISP, 91 64 bytes
(defun R (N)(defvar M (write-to-string N)) (parse-integer (reverse M))) (write (* x (R x)))
(defun R(N)(write(* N(parse-integer(reverse(write-to-string N))))))
Where x N is your integer you want to work with, of course.
I'm pretty new to programming, but I've found that trying these Code Golf problems has been nice practice. Is there something I'm missing that could help with this?
EDIT: Thanks to some tips from ceilingcat, I was able to shave off a few bytes. Old program preserved in strikethrough for reference.
Perl 6, 10 bytes
{$_*.flip}
Expanded
{ # bare block lambda with implicit parameter $_
$_
*
.flip # implicit method call on $_
}
Jelly, 3 bytes
×ṚḌ
I'm new to Jelly, so please let me know if there is a way to do this in 1 or 2 bytes!
Explanation
×ṚḌ (Input: 12)
Ṛ Reversed decimal digits (Stack: [2, 1])
× Multiply by input (Stack: [24, 12])
Ḍ Convert to decimal (Stack: 252)
Implicit print
J, 7 bytes
*|.&.":
Couldn't think of a shorter way, though I feel like this is pretty elegant.
Explanation
*|.&.":
&.": Convert to string, apply next function, then undo conversion
|. Reverse
* Multiply by input
Batch, 87 bytes
@set s=%1
@set r=
:l
@set/ar=r*10+s%%10,s/=10
@if %s% gtr 0 goto l
@cmd/cset/a%1*r
Need to take the arithmetic route here as string reversal fails for some numbers such as 80.
Alice, 9 bytes
//.*
oR@i
Explanation
/ Switch to Ordinal. Move SE.
R. Reverse and duplicate an implicit empty string. Does nothing.
i Read all input as a string.
. Duplicate.
R Reverse.
/ Switch to Cardinal. Move W.
* Implicitly convert the two strings to integers and multiply them.
. Duplicate the result. Irrelevant.
/ Switch to Ordinal. Move NW. Immediately bounces off the wall to move SW instead.
o Implicitly convert the result back to a string and print it.
/ Switch to Cardinal. Move S.
R Reverse the other copy of te result. Irrelevant.
/ Switch to Ordinal. Move NE. Immediately bounces off the wall to move SE instead.
@ Terminate the program.
MATLAB/Octave, 33 31 bytes
@(n)str2num(flip(int2str(n)))*n
Octave/MATLAB anonymous function. This is a pretty naïve approach - converts the integer to a string, flips the string, converts the result back to an integer and multiplies it by the original.
- Save 2 bytes by using
flipinstead offliplr.
Recursiva, 6 bytes
*aI_Va
Explanation:
*aI_Va
*a - multiply by a(input)
I - Integerify
_ - Reverse
V - Stringify
a - a (Input)
JavaScript (SpiderMonkey), 45 35 33 28 bytes
n=>n*[...n].reverse().join``
- Saved 2 bytes thanks to dennis
- Saved 8 bytes thanks to kamoroso94
- Saved 2 bytes thanks to ATaco
- Saved 5 bytes thanks to Shaggy
LOGO, 13 bytes
[?*reverse ?]
Currently there is no TIO for Logo, but you can try it online at http://golf.shinh.org/check.rb . However that's UCBLogo where there is a feature that prints
Thank you for using Logo.
Have a nice day.
on program exit; if this is considered as a function invocation it does not count. (that is, the function does not prints the message)
Usage:
print invoke [?*reverse ?] 123
or
print apply [?*reverse ?] [123]
prints
39483
Husk, 6 bytes
S*(d↔d
Explanation
S*( Multiply the input with the result of the following function applied to the input
d convert number to list of digits
↔ reverse list
d interpret list of digits as number
C# (.NET Core), 60 + 18 bytes
+18 bytes for using System.Linq;.
Reversing strings in C# is a pain.
n=>n*int.Parse(new string(n.ToString().Reverse().ToArray()))
Casio-Basic (fx-CP400), 44 bytes
ExpToStr n,a
StrInv a,a
Print n*strToExp(a)
There's no built-in for reversing an integer, but there is one for reversing a string.
ExpToStr n,a turns n into a string and stores it in a, then StrInv a,a overwrites a with the reversed version of itself. The last line turns a into a number, and prints n*a.
43 bytes for the code, +1 to input n into the parameters box.
Python 3, 35 28 bytes
lambda m:m*int(str(m)[::-1])
Saved 7 bytes by fixing a bug pointed out by Dennis.
Octave, 66 bytes
n=m=input('');j=0;while(m!=0) j=10*j+rem(m,10);m=fix(m/10);end
n*j
Since Octave doesn't have a function to reverse integers, I had to write one myself. That's what the while loop does. Any help will be much appreciated.
05AB1E, 2 bytes
R*
In 05AB1E, integers and strings are treated as equivalent types, so reversal (R) converts to string and reverses, whilst multiplication (*) treats the reverse and the input as integers.
cQuents 0, 8 bytes
#|1:A\rA
Explanation
#|1: Output first term in sequence
A\rA Each term in the sequence equals:
A * \reverse(A)
Mathematica, 19 bytes
# IntegerReverse@#&
Takes an integer input.
RProgN 2, 6 bytes
]Ø.in*
]Ø.in*
] # Duplicate the input to the stack
Ø. # Append a blank string, stringifying the input.
i # Reverse it.
n # Cast to a number.
* # Multiply with the orignal input, implicitely output.