Project Euler Problem 4

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);


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--;

                return false;
            return true;

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


2 thoughts on “Project Euler Problem 4

  1. 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 . 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.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s