-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
51 lines (44 loc) · 1.27 KB
/
Program.cs
File metadata and controls
51 lines (44 loc) · 1.27 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Globalization;
namespace Euler_Problem_0000004
{
class Program
{
static readonly List<long> PalindromeNumbers = new List<long>();
static void Main()
{
// Find the largest palindrome made from the product of two 3-digit numbers
const long max = 998001; // 999 * 999
const long min = 100000; // 100 * 100 = 10000 - Assume the answer is at least six digits. (This could be a wrong assumption.)
// Collect a list of all palindrome numbers from min to max.
for (var i = max; i > min; i--)
{
if (IsPalindrome(i))
{
PalindromeNumbers.Add(i);
}
}
foreach (var palindromeNumber in PalindromeNumbers)
{
for (long i = 999; i > 99; i--)
{
if (palindromeNumber % i == 0)
{
var q = palindromeNumber/i;
if (q > 99 && q < 1000)
{
Console.WriteLine("{0}:{1} * {2}", palindromeNumber, i, q);
Console.Read();
}
}
}
}
}
private static bool IsPalindrome(long l)
{
var s = l.ToString(CultureInfo.InvariantCulture);
return s[0] == s[5] && s[1] == s[4] && s[2] == s[3];
}
}
}