using System;
// This is a C# program that finds the
// smallest perfect square that
// is palindromic in base 10,
// and has an even number of
// digits in base 10.
namespace Enigman_Palindrome_thing
{
class Program
{
static void Main(string[] args)
{
int n = 2; // This is the root of the perfect square.
// Now let's loop through the natural numbers to find
// the palindromic, even digited, perfect square.
bool foundIt = false;
while(!foundIt)
{
int nSquared = n * n; // this is the number to check.
string nSquaredString = nSquared.ToString(); // string form.
// Let the console know which number we're checking.
Console.WriteLine("Currently checking " + nSquaredString);
// check if it has even number of digits.
if((nSquaredString.Length)%2 == 0)
{
// If we're here it's even. Check if it's a palindrome.
bool palindromeFlag = true;
for(int i = 0; i<nSquaredString.Length/2; i++)
{
// If symetric characters are not equal,
// then it's not a palindrome.
if (!(nSquaredString[i]
== nSquaredString[nSquaredString.Length - 1 - i]))
palindromeFlag = false;
}
if(palindromeFlag)
{
// Found it! let's report it to screen
// and finish up.
foundIt = true;
Console.WriteLine(Environment.NewLine
+ "Found it! The number is "
+ nSquaredString + " which is "
+ n.ToString() + " squared.");
}
}
// Increment n for next number to check.
n++;
}
// Keep console alive until ready to leave.
Console.ReadKey();
// Goodbye!
}
}
}