We put together a problem to be solved programmatically, and we know at lower numbers there is a solution to this problem. How would we go about proving whether the below problem has an answer, as our standard computational approaches do not yield a value.
$X$ is the sum of the first $N$ palindromes. Find the value for $N$ in which $X$ is both over $3$ million and is in it's self palindromic.
We used JS to create a function which finds lower values, but the integers are too large to find a solution where x is greater than 3m
function isPalindrome(x) {
const s = `${x}`;
for (let i = 0; i < (s.length - 1) / 2; i++) {
if (s[i] !== s[s.length - i - 1]) return false
}
return true
}
function quickExhaustiveSearch(limit) {
let i = 0,
n = 0, // number of pals
x = 0; // sum of N first pal
console.log(`Solving for x>${limit} starting at i=${i} and n=${n}`);
while (x < limit || !isPalindrome(x)) {
if (isPalindrome(i)) {
x += i;
n++;
console.log({x, i, n});
}
i++
}
console.log('Solution is', x, i, n);
}
FWIW, here's another Python script. It does the same job as Vepir's code, except it uses a generator to construct the palindromes directly so it's a lot faster. It also puts its progress reports on a single line.
some output
That run took 35 seconds on this ancient 2GHz 32 bit machine.