Largest palindrome product - C#

largest palindrome product python
find the largest palindrome made from the product of two 3-digit numbers. node js
largest palindrome product of 2 3-digit numbers python
find the largest palindrome made from the product of two three-digit numbers python
product of palindromes
largest palindrome which is product of two n-digit numbers
largest palindrome product hackerrank
largest palindrome product leetcode

Hello fellow programmers

I'm currently trying to solve some problems on Project Euler in C# to improve my knowledge. However, one solution I made for Problem #4 isn't working even though it should.

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.

Find the largest palindrome made from the product of two 3-digit numbers.

Any ideas?

    namespace ProjectEuler_4
{
    class Program
    {
        static void Main(string[] args)
        {

            for (int i = 999; i >= 100; i--)
            {
                for (int j = 999; j >= 100; j--)
                {
                    if (isPalindome(i *j) == true)
                    {
                        Console.WriteLine("Digit1: " + i);
                        Console.WriteLine("Digit2: " + j);
                        Console.WriteLine("Outcome: " + i * j);
                          Console.ReadLine();
                    }
                    else
                    {

                        Console.WriteLine(i + " " + j + " =nope");

                    }
                }


            }
            Console.ReadLine();
        }
        public static bool isPalindome(int num)
        {
            string sNum = num.ToString();
            for (int i = 0; i < sNum.Length / 2; i++)
                if (sNum[i] != sNum[sNum.Length - 1 - i]) return false;

            return true;
        }

    }
}

Outcome is :

Digit1: 995 Digit2: 583 Total: 580085

Though, that is not the right answer. Anything I did wrong? I'm not asking for a finished solution, just want to understand what the problem is with this one.

Try checking all combinations. For example, 994 * 994 is larger, and you didn't even check it.

Project Euler 4: Largest palindrome product, Any and all suggestions for improvements to either the C# code or the math/​algorithm are very welcome. A palindromic number reads the same  Given a value n, find out the largest palindrome number which is product of two n digit numbers. Examples : Input : n = 2 Output : 9009 9009 is the largest number which is product of two 2-digit numbers. 9009 = 91*99.

Your program actually works and finds the right answer. However, it doesn't print the biggest number first, it's the third output instead.

For example, i=999 j=2 comes before i=998 j=998, but the second product is much bigger. See, you don't find the products in descending order.

The good solution is a simple max-finding loop (kinda-pseudo-code):

var best = -1;
for (i, j) {
  if (isPalindrome(i*j) && i*j > best) {
    best = i*j;
  }
}
Console.WriteLine(best);

Largest palindrome product | C# Online Compiler, A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. 6. ​. 7. Find the  We will find the largest palindrome that is a product of two three-digit numbers. In brute force, there are 810000 comparisons which we have reduced to 362 computations based on three deep insights. Home Discussions Write at Opengenus IQ

Largest palindrome which is product of two n-digit numbers , C# problem to find out the. // largest palindrome number. // which is product of two​. // n digit numbers. using System;. class GFG. {. // Function to calculate largest. Your code checks 995*583 before 993*913 and exits at the first palindrome found, so it doesn't return the largest palindrome. Solution: get the largest palindromes starting from 999*999 = 998001 downwards and check if they can be written as xyz*abc. Or simply use the accepted solution from the question you linked :).

Solution to Project Euler problem 4 in C#, A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 * 99. Find the largest  Next higher palindromic number using the same set of digits Given a palindromic number num having n number of digits. The problem is to find the smallest palindromic number greater than num using the same set of digits as in num .

C, Problem 4 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91  Find the largest palindrome made from the product of two n-digit numbers. Since the result could be very large, you should return the largest palindrome mod 1337.

Project Euler Problem 4 Largest palindrome product in c# (2019 , Largest palindrome product Problem 4 A palindromic number reads the same both ways. The Duration: 10:01 Posted: Mar 28, 2019 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 * 99. Find the largest palindrome made from the product of two 3-digit numbers. I think it is a nice recreational little exercise.

Comments
  • I did, it's starting from 999*999 then 999*998 ect.
  • @Kimo134: Yes, that's the problem, you go (999,999) to (999,1), then (998,999) to (998,1) etc., down to (995,583), and then stop. Check all combinations, find the answer, then think about improving your algorithm, if you want.
  • @Kimo134 The first palindrome found using your looping setup isn't necessarily the largest that's going to be found. If you want to brute force the solution, you have to actually use brute force.