[Question]
  [
An Automorphic number is a number which is a suffix of its square in base 10. This is sequence [A003226](https://oeis.org/A003226) in the OEIS. 
## Your Task:
Write a program or function to determine whether an input is an Automorphic number. 
## Input:
An integer between 0 and 10^12 (inclusive), that may or may not be an Automorphic number. 
## Output:
A truthy/falsy value indicating whether or not the input is an Automorphic number. 
## Examples:
```
0           -> truthy
1           -> truthy
2           -> falsy
9376        -> truthy
8212890625  -> truthy
```
## Scoring:
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), lowest score in bytes wins. 
  
[Answer]
# [Python 2](https://docs.python.org/2/), 24 bytes
```
lambda n:`n*1L`in`n**2L`
```
[Try it online!](https://tio.run/##RYxBDsIgEEX3c4pZlsYFYKxtk96gN6iNoIKS6LQBNp4eaVn4Nu8vXv76ja@FZLLDJb315/bQSL2iWozKUXYtR5WiCfF618EEHHACzPDDLlEki7rjuSmrlUK2HW/kCWYAu3h06Aj/R/2erd5RRFs5BlD2RLjVtNVe09NUgm8wdDaHxOb0Aw "Python 2 – Try It Online")
For the first time in history, Python 2's appending an `L` to the repr of longs is a feature rather than a bug.
The idea is to check if say, `76^2=5776` ends in `76` by checking if `76L` is a substring of `5776L`. To make the `L` appear for non-huge numbers, we multiply by `1L` or have `2L` as the exponent, since an arithmetic operation with a long with produces a long.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 5 bytes
```
~√a₁?
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/v@5Rx6zER02N9v//WxqbmwEA "Brachylog – Try It Online")
## How it works
```
~√a₁?
~√      the input is the square root of a number
  a₁    whose suffix is
    ?   the input
```
[Answer]
# [Python 2](https://docs.python.org/2/), 31 bytes
Out-golfed by xnor... (this happens every single time) >< But hey, it's surprisingly Pythonic for [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'").
People don't tend to remember Python has `str.endswith()`...
```
lambda n:str(n*n).endswith(`n`)
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHPqrikSCNPK09TLzUvpbg8syRDIyEvQfN/SWpxSXxyYnFqsYKtQjSXAhAY6IApQwhlBKEsjc3NICwLI0MjC0sDMyNTrlgurrT8IoVMhcw8BYRBVmBlBUWZeSUKaRqZmv8B "Python 2 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
n.s¹å
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/T6/40M7DS///tzQ2NwMA "05AB1E – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina), 44 bytes
```
$
;918212890625;81787109376;0;1;
^(\d+;).*\1
```
[Try it online!](https://tio.run/##K0otycxL/P9fhcva0tDCyNDIwtLAzMjU2sLQ3MLc0MDS2NzM2sDa0JorTiMmRdtaU08rxvD/f5AwAA "Retina – Try It Online")
There are exactly 4 solutions to the 10-adic equation `x*x = x`.
[Answer]
## [Alice](https://github.com/m-ender/alice), 17 bytes
```
/o.z/#Q/
@in.*.L\
```
[Try it online!](https://tio.run/##S8zJTE79/18/X69KXzlQn8shM09PS88n5v9/czMA "Alice – Try It Online")
Outputs nothing (which is falsy in Ordinal mode) or `Jabberwocky` (which is non-empty and therefore truthy in Ordinal mode; it's also the canonical truthy string value).
### Explanation
```
/.../#./
....*..\
```
This is a slight modification of the general framework for linear Ordinal mode programs. The `/` in the middle is used to have a single operator in Cardinal mode in between (the `*`) and then we need the `#` to skip it in Ordinal mode on the way back. The linear program is then:
```
i..*.QLzno@
```
Let's go through that:
```
i    Read all input as a string and push it to the stack.
..   Make two copies.
*    This is run in Cardinal mode, so it implicitly converts the top two
     copies to their integer value and multiplies them to compute the square.
.    Implicitly convert the square back to a string and make a copy of it.
Q    Reverse the stack to bring the input on top of the two copies of its square.
L    Shortest common supersequence. This pops the input and the square from
     the top of the stack and pushes the shortest string which begins with
     the square and ends with the input. Iff the square already ends with the
     input, this gives us the square, otherwise it gives us some longer string.
z    Drop. Pop the SCS and the square. If the square contains the SCS (which
     would mean they're equal), this removes everything up to the SCS from
     the square. In other words, if the SCS computation left the square
     unchanged, this gives us an empty string. Otherwise, it gives us back
     the square.
n    Logical not. Turns the empty string into "Jabberwocky" and everything
     else into an empty string.
o    Print the result.
@    Terminate the program.
```
[Answer]
# Mathematica, 31 bytes
```
Mod[#^2,10^IntegerLength@#]==#&
```
[Try it online!](https://tio.run/##y00sychMLv6fZvvfNz8lWjnOSMfQIM4zryQ1PbXIJzUvvSTDQTnW1lZZ7X9AUWZeiYJDmoKDqaWloYWRoZGFpYGZkel/AA "Mathics – Try It Online") Mathics prints an extra message but the answer is correct
[Answer]
# Python 2, ~~37~~ ~~33~~ ~~30~~ 29 bytes
```
lambda n:n*~-n%10**len(`n`)<1
```
Saved 4 bytes thanks to @LeakyNun.
Saved 3 bytes by noticing that the input is lower than 10^12 so `n` doesn't end with an "L".
Saved 1 byte thanks to @Dennis because I miscounted in the first place.
[Try it online!](https://tio.run/##K6gsycjPM/pfUJSZV6KQlplTklqk8T8nMTcpJVEhzypPq043T9XQQEsrJzVPIyEvQdPG8L@OQlFiXnqqhqEBGGhq/gcA) (TIO link courtesy of @Dennis).
[Answer]
# Ruby, 22 bytes
```
->n{"#{n*n}"=~/#{n}$/}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWkm5Ok8rr1bJtk4fyKpV0a/9H82loGCgAyQMQYQRiLA0NjcD0RZGhkYWlgZmRqZcsXqpickZCtUKNXk1CgWlJcUKiopp0XmxCrX/AQ "Ruby – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 57 bytes
```
f(__int128 n){n=n*n%(long)pow(10,printf("%u",n))==n;}
```
Based on @betseg's answer, this is a function that returns **1** or **0**. It produces garbage output to STDOUT, which is [allowed by default](https://codegolf.meta.stackexchange.com/a/9658/12012).
The score contains **+4 bytes** for the compiler flag `-lm`.
[Try it online!](https://tio.run/##VY9NasQwDIXX0SlESordSZ1kVoX8nKQwuE48MThy8NjtYpizp6Ltpto8CYnv6X3o23oYnXBCnVPYQtxXZ5TBYUB1WHG5OErd@Q1J3mmkF6qED3SVe/gSXVvvkddWlFUua5JyHKl/HE@OjM/zgsMtzS6odQLgM9y0IyHhDoUNEX84SDhi27MM2LW/xdPpJKEonEVhBWO5L@yfFSOXGGssq/mdypr/6uEBCuBqDL767X8MUI1WISc8T88dZ2zm5bOh7P3xDQ "Bash – Try It Online")
[Answer]
# R, 28 bytes
```
pryr::f(x^2%%10^nchar(x)==x)
```
Creates a function:
```
function (x) 
x^2%%10^nchar(x) == x
```
Takes the modulus of `x^2` such that we keep the last digits, which we compare to `x`.
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 47 bytes
```
n=>$"{BigInteger.Multiply(n,n)}".EndsWith(n+"")
```
[Try it online!](https://tio.run/##TY1Bq8IwEITv/RVL8ZDyNBdFeVQ9KAqCiqjgOaRrXWg3kk0Fkf722gqCc5sZ5hsrA@s8NpUQ53B6SsAyjX6d3lclerKSRrYwInDwLvemfEUAEkwgCw9HGewMsUq6FGBdsZ1uOIxH/YVzBRqewxVmDc/mvfi1oLztMEevd1UR6F48Ffc5qWO94kwuFG6K/@I4aTpW@iEuHUsL0hdPAdVVtf6BPuiz@9yob39Ek22JUSWtumkd1c3/cDJ@Aw "C# (.NET Core) – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 12 11 bytes
```
Ｉ¬⌕⮌ＩＸＩθ²⮌θ
```
[Try it online!](https://tio.run/##S85ILErOT8z5///9npWH1jzqmfpoXQ@Q@X7PDiB5bsehTUD@uR3//1sam5sBAA "Charcoal – Try It Online")
Returns `False` as `falsey` and `True` as `truthy`.
* 1 byte saved thanks to ASCII-only! (How could I miss the `Power` function?)
[Answer]
# JavaScript (ES6), 23 bytes
```
n=>`${n*n}`.endsWith(n)
```
---
## Try it
Wrote this Snippet up on my phone, so please edit if it's not working correctly.
```
f=
n=>`${n*n}`.endsWith(n)
oninput=_=>o.innerText=f(+i.value);o.innerText=f(i.value=1)
```
```
<input id=i type=number><pre id=o>
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
²ṚwṚ⁼1
```
[Try it online!](https://tio.run/##y0rNyan8///Qpoc7Z5UD8aPGPYb///@3NDY3AwA "Jelly – Try It Online")
[Answer]
# Kotlin, 36 bytes
```
fun a(i:Int)="${i*i}".endsWith("$i")
```
[Answer]
# C, 77 + 4 (`-lm`) = 81 bytes
```
#import<tgmath.h>
i;f(long double n){i=fmod(n*n,pow(10,(int)log10(n)+1))==n;}
```
[Try it online!](https://tio.run/##XY1LDoIwFEXnrIJoSPoUhMZIUcSVOMFiS5P2lWCNA8LWrTJSGN5zfzyRnHu/VqazvTs7aWrX7tpLoEpBtEUZNvZ50/cQYVCVMLYhuMG4sy9Cs5godKCtpBlB2FKAqsJy9GlqaoUEhq7/BgRZRc0qFiQHKMdgYRWUFYxmxz07nMKoueIP5EvAJjAt/ZVgJvO5ZNOjf3Oha/nwiTYf "C (gcc) – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 15 + 1 (-p) = 16 bytes
```
$_=$_**2=~/$_$/
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3lYlXkvLyLZOXyVeRf//f9N/@QUlmfl5xf91CwA "Perl 5 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
²_ọæċ⁵$
```
[Try it online!](https://tio.run/##y0rNyan8///QpviHu3sPLzvS/ahxq8r///8tjc3NAA "Jelly – Try It Online")
Positive number for yes, 0 for no.
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~47~~ 33 bytes
14 bytes thanks to Martin Ender.
```
.+
$*
$
¶$`
\G1
$%_
M%`1
(.+)¶\1$
```
[Try it online!](https://tio.run/##K0otycxL/P9fT5tLRYtLhevQNpUErhh3Qy4V1XguX9UEQy4NPW3NQ9tiDFX@/zc3AwA "Retina – Try It Online")
[Answer]
# [PHP](https://php.net/), 41 bytes
```
<?=preg_match("#$argn$#",bcpow($argn,2));
```
[PHP Sandbox Online](http://sandbox.onlinephpfunctions.com/code/bd634da28574a838b859407ccbc0f911cb4729fc)
# [PHP](https://php.net/), 42 bytes
without Regex
```
<?=strtr(bcpow($argn,2),[$argn=>X])[-1]>A;
```
# [PHP](https://php.net/), 44 bytes
Use the [levenshtein](http://php.net/manual/en/function.levenshtein.php) distance
```
<?=!levenshtein($argn,bcpow($argn,2),0,1,1);
```
[Answer]
# [Dyvil](https://github.com/dyvil/Dyvil), 26 bytes
```
x=>"\(x*x)".endsWith"\(x)"
```
Usage:
```
let f: int->boolean = x=>"\(x*x)".endsWith"\(x)"
print(f 20) // false
```
[Answer]
## Batch, 122 bytes
```
@set/an=%1,t=f=1
:l
@set/at+=t,f*=5,n/=10
@if %n% gtr 0 goto l
@cmd/cset/a"(!(%1%%t)|!(~-%1%%t))&(!(%1%%f)|!(~-%1%%f))
```
Algorithm is limited only by the integer type used for variables. In the case of Batch, this is 32-bit signed integers, so the maximum is 2147483647. Works by testing both n and n-1 for necessary powers of 2 and 5 as factors. (Except when n is 0 or 1, n and n-1 will have one factor each.)
[Answer]
## [><>](https://esolangs.org/wiki/Fish), 30 bytes
```
1&0}\{n;
:&(?\:::*&a*:&%={+}:&
```
[Try it online](https://tio.run/##S8sszvj/31DNoDamOs@ay0pNwz7GyspKSy1Ry0pN1bZau9ZK7f///7plCqaWloYWRoZGFpYGZkamAA "><> – Try It Online"), or watch it at the [fish playground](https://fishlanguage.com/playground)!
Assumes the input number *x* is already on the stack.
Explanation: The fish takes the quotient of *x*2 by increasing powers of 10, and counts how many times this equals *x*. When the power of 10 gets larger than *x*, it prints the count and halts. The count will be 1 if *x* is automorphic, and 0 if it isn't.
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 23 bytes
```
n->n^2%10^#digits(n)==n
```
[Try it online!](https://tio.run/##FcrdBoBAEIbhW/mUaJlld9LfwXYjKSJlyRjVSVe/1dn78OpyRrtr2hCQxA4yc@HdnK9xj/dViglB0qJ6PKXADtAzyv1l9iPD9h2GMDqCJzChr9qG0LHnrncN15NJLw "Pari/GP – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~10~~ 9 bytes
-1 byte thanks to [isaacg](https://codegolf.stackexchange.com/users/20080/isaacg).
```
x_`^vz2_z
```
Returns 0 when the number is automorphic, anything else if it is not.
[Test it online!](https://pyth.herokuapp.com/?code=x_%60%5Evz2_z&input=8212890625&debug=0)
**Explanations**
```
x_`^vz2_z
   ^vz2      # Evaluate the input to a number, compute the square
  `          # Convert the squared number to a string
 _           # Reverse it
x      _z    # Find the index of the first occurrence of the reversed input in the reversed square. That's basically equivalent of doing an endswith() in Python
             # Implicit input of the index. If 0, then the reversed square starts with the reversed input
```
[Answer]
# [Rexx (Regina)](http://www.rexx.org/), 48 bytes
```
numeric digits 25
arg n
say right(n*n,length(n))=n
```
[Try it online!](https://tio.run/##K0qtqPj/P680N7UoM1khJTM9s6RYwdSAK7EoXSGPqzixUqEoMz2jRCNPK08nJzUvvSRDI09T0zbv/39LY3MzMAEA "Rexx (Regina) – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 45 bytes
```
f=reverse.show
g a=and$zipWith(==)(f a)$f$a^2
```
[Try it online!](https://tio.run/##BcGxCoAgEADQva9wcNBFrOb7joYoOOjUIzNRKejn7b2A9aQYe3dQ6KFSydRwv4MXCJgO@XFeuAUFoJUTqKWTuE/9Qk6QC6cmHcdGRfh1NGa2dus/ "Haskell – Try It Online")
# [Haskell](https://www.haskell.org/) + [Data.Function](http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Function.html), 42 bytes
```
g a=and$on(zipWith(==))(reverse.show)a$a^2
```
[Try it online!](https://tio.run/##BcExDsMgDADArzAwwIKSLJnYqn6hQ5VKVuoGK8Qg4zRSP0/vErQdc@501CJqbqAQ7ievSoX7ZiACv21h96P6IE0uRu@d4BelYWipXB4svKZ@AHGsQqz2Q1lRzPYcQ5iHYel/ "Haskell – Try It Online")
```
and.(on(zipWith(==))(reverse.show)<*>(^2))
```
[Try it online!](https://tio.run/##BcExDsIwDADAr3RgsBmswsJCmBBfYEBUisA0FqkTOYZKfD7cpdjenHOXpRbz4Rw90uWjD5eifQ5RnwRF4Sf1Kp4gBEQw/rI1ppbKisftCaY9Yl@iaKgm6puXZGcb5tuO6DCO9/4H "Haskell – Try It Online")
# [Haskell](https://www.haskell.org/) + [Data.Function](http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Function.html) + [Control.Monad](http://hackage.haskell.org/package/base-4.10.0.0/docs/Control-Monad.html), 40 bytes
```
and.ap(on(zipWith(==))$reverse.show)(^2)
```
[Try it online!](https://tio.run/##LcihDsIwEABQz1dMTLTmMmZQVRAceoKw5MLKeqG7a64HJPx8MTz5EtZnzLnRVkStO6EhnF98NxLe/fMobCoZLsK4tDUgL4DFCbsvlYksuRC87zW@o9YINcnHu3n0bUPiUJTY@gdli9qt1z3AYRhu7Qc "Haskell – Try It Online")
[Answer]
# [PowerShell Core](https://github.com/PowerShell/PowerShell), ~~36~~ 34 bytes
```
param([bigint]$a)""+$a*$a|% En* $a
```
[Try it online!](https://tio.run/##VY/LasJQEIbXOU8xyFgSq6ARrVKEQOm6UpcS5CROrCW3ngstaJ79dFJjxeX334apq29S@oPyfJRWihxmq5OrpZKFv02Oh2NpYpRBr/eIcoDy3IfXcgAoXSNE5AtvGPnjIaBRloI/mtxRyJTJXHe4nD7N7/xFOAkXy/E8nP3LAZyhDyfhYWmLhBQb9FNTamgPK8AdG4q0zQ3TA2bQxYS3XW9erDZV8ZZ8cjyOeMPb2DQlrdtm1xrR122RE@v2VzKk2sxl65nl9@uNrsdaIxrnfgE "PowerShell Core – Try It Online")
Could be 8 bytes shorted if passing a `bigint` as parameter was allowed
-2 bytes thanks to *Zaelin Goodman*!
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `r`, 3 bytes
```
²øf
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJQciIsIiIsIsKyw7hmIiwiIiwiNjciXQ==)
First time using the `r` flag.
]