Search This Blog

Wednesday, December 29, 2010

Euler Problem 40

Brute force attack!!!

Keep making the string longer until you hit 1 million chars long.. then do the calc they want.. rem first place is s[0]…. and you’re sorted!

____

static void Main(string[] args)
{
    string s = "";
    int i=0;
    while (s.Length<1000001)
   {
       i++;
        s += i.ToString();
    }

    int sum = (Convert.ToInt32(s[0])-48) * (Convert.ToInt32(s[9])-48) * (Convert.ToInt32(s[99])-48) * (Convert.ToInt32(s[999])-48) * (Convert.ToInt32(s[9999])-48) * (Convert.ToInt32(s[99999])-48) * (Convert.ToInt32(s[999999])-48);
   
 
    Console.WriteLine("Answer>>"+sum);
    Console.ReadLine();

}

No comments: