Wednesday, April 16, 2014

(Solved) Error: Uncaught Sys.ArgumentTypeException: Sys.ArgumentTypeException: Object of type 'Sys.Extended.UI.Animation.GenericAnimationBehavior' cannot be converted to type 'Sys.UI.Behavior'. Parameter name: instance in ASP.NET

Error:

Uncaught Sys.ArgumentTypeException: Sys.ArgumentTypeException: Object of type 'Sys.Extended.UI.Animation.GenericAnimationBehavior' cannot be converted to type 'Sys.UI.Behavior'. Parameter name: instance
Solution:

Error resolved by adding ScriptMode="Release" like below
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release">
</asp:ScriptManager>
or
<asp:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server"  ScriptMode="Release">
</asp:ToolkitScriptManager>

(Solved) Error: Uncaught TypeError: Cannot read property 'UI' of undefined in ASP.NET

Error:

Uncaught TypeError: Cannot read property 'UI' of undefined
Solution:

Error Resolved by Changing,
<asp:ScriptManger>
to
<asp:ToolScriptManager>

Note: You need to add the latest Ajax Control Toolkit in your Visual Studio Toolbox to access the <asp:ToolScriptManager>

Thursday, April 10, 2014

Project Euler Solution using C#: Problem 16: Power Digit Sum

Problem:

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
My Solution:

static void Main(string[] args)
{
    int pwr = 1000;
    int sum = 0;
    BigInteger l =(BigInteger)Math.Pow(2, 1000);
    foreach (var item in l.ToString().ToCharArray())
    {
        sum += Int32.Parse(item.ToString());
    }
    Console.WriteLine(sum);
    Console.ReadLine();
}

Note:
You can simplifies the coding :)

Project Euler Solution using C#: Problem 12: Highly Divisible Triangular Number

Problem:

The sequence of triangle numbers is generated by adding the natural numbers.
So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
Let us list the factors of the first seven triangle numbers:
1: 1
3: 1,3
6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28
We can see that 28 is the first triangle number to have over five divisors.
What is the value of the first triangle number to have over five hundred divisors?
My Solution:

static void Main(string[] args)
{
    int length = 1;  
    bool isFound = false;
    int divCount = 500;
    while (isFound == false)
    {
        int triNum = 0;
        int factorsCount = 0;
        for (int i = 1; i <= length; i++)
        {
            triNum += i;
        }
        for (int i = 1; i <= triNum; i++)
        {
            if (triNum % i==0)
            {
                factorsCount += 1;
                if (factorsCount > divCount)
                {
                    Console.WriteLine(factorsCount);
                    Console.WriteLine(triNum);
                    isFound = true;
                    break;
                }
            }
        }
        length += 1;
    }
    Console.ReadLine();
}

Note:
You can simplifies the coding :)

Project Euler Solution using C#: Problem 10: Summation Of Primes

Problem:

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million.
My Solution:

static void Main(string[] args)
{
    bool isPrime = false;
    long limit = 2000000;
    long ans = 2;
    for (long i = 3; i < limit; i += 2)
    {
            for (long j = 2; j < i; j++)
            {
                if (i % j != 0 && i != j)
                {
                    isPrime = true;
                }
                else
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                Console.Clear();
                ans += i;
                Console.WriteLine(ans);
            }
    }
    Console.WriteLine("The sum of all the primes below " + limit + " is : " + ans);
    Console.ReadLine();
}

Note: You can simplifies the coding :)

Project Euler Solution using C#: Problem 9: Special Pythagorean Triplet

Problem:

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
My Solution:

static void Main(string[] args)
{
    int total = 1000;
    for (int i = 1; i <= total; i++)
    {
        for (int j = 1; j <= total; j++)
        {
            int k = total - i - j;
            int res = (i * i) + (j * j) + (k * k);
            int r = i + j + k;

            int left = (i * i) + (j * j);
            int right = (k * k);

            if (left == right && i < j && j < k)
            {
                Console.WriteLine(i + " " + j + " " + k);
                Console.WriteLine(Math.Pow(i, 2) + " " + Math.Pow(j, 2) + " " + Math.Pow(k, 2));
                Console.WriteLine(i * j * k);
                Console.WriteLine("---------------------");
            }
        }
    }
    Console.ReadLine();
}

Note: You can simplifies the coding :)