-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem04.cs
31 lines (31 loc) · 1.02 KB
/
Problem04.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace Miller.ProjectEuler.Solutions
{
/// <summary>
/// Largest palindrome product
/// </summary>
/// <seealso cref="https://projecteuler.net/problem=4"/>
public class Problem04
{
/// <summary>
/// Uses a nested loop to generate products for every 3-digit number between 100 and 999.
/// Each product is checked if it is a palindrome.
/// </summary>
/// <returns>The largest palindrome product. Ranges are hardcoded so the result is always 906,609.</returns>
public int Solve()
{
var largestPalindrome = 0;
for (int i = 100; i <= 999; i++)
{
for (int j = 100; j < 999; j++)
{
var product = i * j;
if (product > largestPalindrome && product.ToString().IsPalindrome())
{
largestPalindrome = product;
}
}
}
return largestPalindrome;
}
}
}