Have decided to try and get a few of these done every week just to keep the ol’ brain alive. Here’s my working for Project Euler problem 4 in C#.

class Program
{
static void Main(string[] args)
{
int biggest = 0;
for (int i = 100; i < 999; i++)
for (int j = 100; j < 999; j++)
{
int product = i * j;
if (IsPalindromic(product))
if (product > biggest)
biggest = product;
}
Console.WriteLine("Done!, biggest was " + biggest);
Console.ReadKey();
}
}

Where “IsPalindromic” is as follows…

public static bool IsPalindromic(int number)
{
string s = number.ToString();
int frontCounter = 0;
int backCounter = s.Length-1;
while (frontCounter < backCounter)
{
if (s[frontCounter] == s[backCounter])
{
frontCounter++; backCounter--;
continue;
}
return false;
}
return true;
}

brute force… but for something this trivial I don’t care 😛

### Like this:

Like Loading...

*Related*

Cool stuff, looking forward to seeing more. I started solving Project Euler problems in Haskell this past week and will be posting solutions on my blog at http://austinprete.blogspot.com . I don’t know that you have any interest in Haskell though. Anyway, C# is my other main language at the moment so it’s good to see people working on Project Euler in it.

Looping from 999 downwards is more efficient because that way the first palindrome you come across has to be the final solution.