Skip to content

Instantly share code, notes, and snippets.

@hallatore
Created December 2, 2014 10:10
Show Gist options
  • Select an option

  • Save hallatore/385daf326b3b11618865 to your computer and use it in GitHub Desktop.

Select an option

Save hallatore/385daf326b3b11618865 to your computer and use it in GitHub Desktop.
private static void Test()
{
var sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000; i++)
{
var count = GetPalindromic(10000000000000000000);
}
var elapsed = sw.ElapsedMilliseconds;
Console.WriteLine("Elapsed: {0}ms", elapsed); // Elapsed: 5 ms
}
private static int GetPalindromic(UInt64 number)
{
var count = 0;
for (UInt64 i = 10; i <= number; i*= 10)
{
var l = i.ToString().Length;
var f = Math.Floor(l/2.0);
count += (int)(0.9 * Math.Pow(10, f));
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment