The number 47 has an interesting characteristic.
If you take the number, plus its reverse (47 => 74) and then add them together to a number (47+74=121) the resulting sum is a palindrome
Starting at 0, find the first 25 numbers that have this same characteristic as 47, but limit it to where the palindrome is greater than 1000.
Collect the results in an array. Be sure that you're collecting the interesting numbers like 47, not the palindromic sums.
Bonus points if you can do this without converting numbers to strings/arrays.
Limit your online searches to core language documentation only.
- Copy this markdown and paste in your own, private gist
- In your private gist, fill out the questions below
- Submit by the due time as instructed in Zoom
What assumptions will you make about this problem if you cannot ask any more clarifying questions? What are your reasons for making those assumptions?
I think it's safe to assume the first number pair will be greater than 100. Maybe I can start this function there to skip over the first 100 iterations of trying to find two numbers.
It seems simple enough at first. The hardest part seems to be reversing the number without using strings.
- Searching of Data
- Sorting of Data
- Pattern Recognition
- Build/Navigate a Grid
- Math
- Language API knowledge
- Optimization
I think it would be best to hold data in an array. It says we need the first 25 numbers, so I think this is a fair assumption.
I'll need a function to reverse the number. I can use this same function to check that the total is a palindrome (against itself). If it is, I'll push the origional number into an array, to save it. I'll then need a function to run this code until there are 25 numbers in the array.
let pNums = [];
function reverseNumAsString(num) {
return ('', + num).split('').reverse().join('')
}
function findPNums(num) {
let total = num + reverseNumAsString(num);
if (total == reverseNumAsString(total) && total >= 1000)
pNums.push(num)
}
function fillPNums() {
let incrimentor = 0;
if(pNums.length < 25) {
findPNums(incrimentor);
incrimentor ++
}
}
I'm not 100% confident on this number, but I believe it's O(n).