problem 5 solution

This commit is contained in:
Colin McMillen 2020-11-17 14:36:40 -05:00
parent e6a6bd34f6
commit db9e9a33f4

View File

@ -5,6 +5,18 @@ namespace Euler {
class Program {
static void Debug(long l) {
Console.WriteLine(l);
}
static void Debug(string s) {
Console.WriteLine(s);
}
static void Debug(bool b) {
Console.WriteLine(b);
}
static long Problem1() {
long sum = 0;
for (long i = 1; i < 1000; i++) {
@ -70,8 +82,35 @@ namespace Euler {
return highestPrimeFactor;
}
static bool IsPalindromicNumber(long l) {
string s = "" + l;
for (int i = 0; i < s.Length / 2; i++) {
if (s[i] != s[s.Length - i - 1]) {
return false;
}
}
return true;
}
static long Problem4() {
long largest = 0;
for (long i = 999; i >= 100; i--) {
for (long j = 999; j >= 100; j--) {
long target = i * j;
if (target < largest) {
continue;
}
if (IsPalindromicNumber(target)) {
largest = target;
Debug(largest);
}
}
}
return largest;
}
static void Main(string[] args) {
Console.WriteLine(Problem3());
Debug(Problem4());
}
}
}