18
2
In this task you will take as input a non-negative integer \$n\$, and output the number of pairs of non-negative integers \$a,b\$ such that both are palindromes*, \$a \leq b\$, and \$a+b = n\$. For example if \$n\$ is \$22\$ then the valid pairs are
\$ \begin{array}{c|c} a & b \\ \hline 0 & 22 \\ 11 & 11 \\ \end{array} \$
So the output is \$2\$.
As another example, if \$n\$ is \$145\$ then the valid pairs are
\$ \begin{array}{c|c} a & b \\ \hline 4 & 141 \\ 44 & 101 \\ \end{array} \$
So the output is 2.
Your submission should be a program or function. Answers will be scored in bytes with fewer bytes being the goal.
Test Cases
\$ \begin{array}{c|c c|c} \mathrm{Input} & \mathrm{Output} & \mathrm{Input} & \mathrm{Output} \\ \hline 0 & 1 & 12 & 5\\ 1 & 1 & 13 & 4\\ 2 & 2 & 14 & 4\\ 3 & 2 & 15 & 3\\ 4 & 3 & 16 & 3\\ 5 & 3 & 17 & 2\\ 6 & 4 & 18 & 2\\ 7 & 4 & 19 & 1\\ 8 & 5 & 20 & 1\\ 9 & 5 & 21 & 0\\ 10 & 5 & 22 & 2\\ 11 & 5 & 23 & 1\\ \end{array} \$
* In base 10
1Related – Luis Mendo – 2020-02-02T17:16:01.167
7I like how this challenge was posted on a palindromic date, 02/02/2020 – James – 2020-02-02T17:56:01.537
3@DJMcMayhem Additionally the number of days since the beginning of the year (33) and the number of days to the end of the year (333) today are both palindromes. – Post Rock Garf Hunter – 2020-02-02T17:57:27.927
3
@DJMcMayhem I think you mean 20200202 or 2020-02-02 (ISO 8601) -- today is special, it is palindromic in the UK, the US, and internationally.
– Jonathan Allan – 2020-02-02T18:26:04.847