# Am I an Automorphic Number?

An Automorphic number is a number which is a suffix of its square in base 10. This is sequence A003226 in the OEIS.

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 , lowest score in bytes wins.

• Btw the limit of 1e12 means submissions will need to handle numbers up to 1e24, which is an 80-bit number. If handling numbers that large is a hard requirement, many of the exiting answers are invalid. – Dennis Jun 24 '17 at 19:59
• Need we handle numbers that would lead to precision issues in our chosen language? – Shaggy Jun 24 '17 at 21:50
• Provided that you don't abuse the standard loophole about that, then that would be fine. – Gryphon Jun 24 '17 at 22:49
• Specifically, this loophole – Gryphon Jun 24 '17 at 22:53
• It's been a loooong day and I am very, very tired but your comments read to me as validating my JS solution. Could you confirm that? (No issue deleting if not) – Shaggy Jun 24 '17 at 23:40

# Java 8, 36 bytes

n->(n.multiply(n)+"").endsWith(n+"")


Input is a java.math.BigInteger, output a boolean.

Explanation:

Try it here.

n->                   // Method with BigInteger parameter and boolean return-type
(n.multiply(n)+"")  //  Return if the String representation of n*n
.endsWith(n+"")    //  ends with the String representation of n
// End of method (implicit / single-line body)


# Python 3, 40 35 bytes

-@Nick A saved 5 bytes: use of endswith()

lambda x:str(x*x).endswith(str(x))


Try it online!

# Python 2, 31 bytes (Does not work for large numbers)

lambda x:x*x[-len(x):]==x


Try it online!

• Doesn't work on 8212890625 because x*x will end with "L". You can however save two bytes by removing the f= I think. – nore Jun 24 '17 at 19:07
• It would work in python 3 though, right? – officialaimm Jun 24 '17 at 19:15
• You must use f=\ not f=/... – Erik the Outgolfer Jun 24 '17 at 19:15
• Yes that will work then. – nore Jun 24 '17 at 19:19
• Would using endswith and removing s=str not be shorter for python3?: lambda x:str(x*x).endswith(str(x)) – user52452 Jun 26 '17 at 10:20

f=reverse.show
g a=and$zipWith(==)(f a)$f$a^2  Try it online! # Haskell + Data.Function, 42 bytes g a=and$on(zipWith(==))(reverse.show)a$a^2  Try it online! # Haskell + Data.Function + Control.Monad, 40 bytes and.ap(on(zipWith(==))$reverse.show)(^2)