Example #1
0
        /*
         * SOLVED
         * Problem: Find the largest palindrome made from the product of two 3-digit numbers.
         */
        public static void ProblemAnswer()
        {
            /*Better than a brute force method*/
            int largestPalindrome = 0;

            for (int x = 999; x >= 100; x--)
            {
                for (int y = 999; y >= x; y--)
                {
                    int product = x * y;

                    if (product <= largestPalindrome)
                    {
                        break;
                    }

                    if (EulerHelper.IsPalindrome(product))
                    {
                        largestPalindrome = product;
                    }
                }
            }

            Console.WriteLine("Euler Problem 4 Answer: " + largestPalindrome);
            Console.Write("Press ENTER to continue.");
            Console.ReadLine();
        }
Example #2
0
        /*
         * SOLVED
         * Problem: What is the largest prime factor of the number 600851475143?
         */
        public static void ProblemAnswer()
        {
            var bigNum = 600851475143;

            for (var i = 2; i *i < bigNum; i++)
            {
                if (bigNum % i == 0 && EulerHelper.IsPrime(i))
                {
                    bigNum /= i;
                }
            }

            Console.WriteLine("Euler Problem 3 Answer: " + bigNum);
            Console.Write("Press ENTER to continue.");
            Console.ReadLine();
        }
Example #3
0
        /* SOLVED
         *
         * Problem: By considering the terms in
         * the Fibonacci sequence whose values do not exceed
         * four million, find the sum of the even-valued terms.
         */

        public static int Fib(int n)
        {
            return(EulerHelper.FibNthValue(n));
        }