Thank you yet again! Now I just need to figure out why it's telling me 998001 is the correct answer considering that it's not a palindrome. To Monodevelop, AWAY!
Edit: With a small tweak I'm now getting 900099 as an answer. I'm close, I can feel it. This is why I love programming.
Edit2: It is a problem with the testing for the palindrome part (not that it could hardly be any other part). Putting it into a blank solution with a known palindrome it doesn't seem to acknowledge it.
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Listtest {
class MainClass {
public static void Main (string[] args) {
List<int > digits = new List<int> ();
digits.Add (1);
digits.Add (2);
digits.Add (3);
digits.Add (2);
digits.Add (1);
if (digits.Last () == digits.First ()) {
if (digits [digits.Count () - 1] == digits [1]) {
if (digits.Count () > 5) {
if (digits [digits.Count () - 2] == digits [2]) {
Console.WriteLine (digits [1]); // Just to see output
}
} else
Console.WriteLine (digits [2]); // Just to see output
}
}
}
}
}
I've been staring at it for a while now, and seem to be stumped. Will continue for a bit longer before heading off to bed though.
Edit: Trying a new way now. Using a loop to check for palindrome. Going to bed now, leaving code here for random code-solving super hero to solve. I'm utterly stumped as to why neither one was working. :/
Code:
// Find the largest palindrome made from the product of two 3-digit numbers.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Euler4 {
class MainClass {
public static void Main (string[] args) {
const int max = 999;
bool isPalindrome = false;
int largest = 0;
int num = 0;
for (int x = 100; x <= max; x++) {
for (int y = 100; y <= max; y++) {
int current = num = x * y;
List<int > digits = new List<int> ();
while (num > 0) {
digits.Add (num % 10);
num = num / 10;
}
int a = 0;
int b = digits.Count () - 1;
while (a < b) {
if (digits [a] == digits [b])
isPalindrome = true;
a++;
b--;
}
if (isPalindrome)
largest = current;
}
}
Console.WriteLine (largest);
}
}
}