Browse Source

problem 5 solution

main
Colin McMillen 11 months ago
parent
commit
db9e9a33f4
  1. 41
      Program.cs

41
Program.cs

@ -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());
}
}
}
Loading…
Cancel
Save