Created
February 15, 2014 11:44
-
-
Save kashwaa/9018210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
Stopwatch sw = new Stopwatch(); | |
sw.Start(); | |
Dictionary<int, int> results = new Dictionary<int, int>(); | |
int i1 = 999, i2 = 999; | |
int biggest1 = 0, biggest2 = 0; | |
while (biggest1 <= biggest2) | |
{ | |
for (int i = i1; i > biggest1; i--) | |
{ | |
if (isPalindromic(i * i2)) | |
{ | |
results.Add(i, i2); | |
i2--; | |
biggest1 = i; | |
biggest2 = i2; | |
break; | |
} | |
} | |
i2--; | |
} | |
var result = results.Max(c => c.Key * c.Value); | |
sw.Stop(); | |
Console.WriteLine(result); | |
Console.WriteLine(sw.Elapsed); | |
Console.ReadLine(); | |
} | |
static bool isPalindromic(int n) | |
{ | |
bool res = true; | |
string sN = n.ToString(); | |
for (int i = 0; i <sN.Length/2; i++) | |
{ | |
if (sN[i]!=sN[sN.Length-1-i]) | |
{ | |
return false; | |
} | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment