Check if a number is the mirror image of itself

Given an arbitrarily large number, how to check if it is same as it’s mirror image.

For example 101 is a mirror image of itself, where as 1811 is not a mirror image of itself.

This problem is from Hacker earth (A website for competitive programming). If you want to solve this problem on your own, and execute it on different possible test cases for it’s correctness, follow this link. If you just want to know the solution, read on…

The solution is simple; the number should only contain the digits from the set {0,1,8} because they look the same when read in a mirror and it should also be a palindrome.

Here is the simple program to do this.

Leave a Reply

Your email address will not be published. Required fields are marked *