Gap in count of bases for which a number's representation is palindromic (by concatenation of decimal representations)

286 Views Asked by At

I have written a small program that calculates the base representation of a number, and checks if that representation is a palindrome (also check if the length is at least 2, since a length of 1 is trivially palindromic).

What I have found is that there is a "gap", which becomes larger as the numbers that are considered goes higher. In the image below, I have considered all numbers from 2 to 30000. There also seems to be 2 smaller gaps forming in between each of the "segments".

Is there a reason that there is a gap?

Edit: the condition on being palindromic are considering the concatenation of the decimal representations using code found here: https://stackoverflow.com/questions/10184577/java-recursion-program-convert-a-base-10-number-to-any-base. For example, I consider 5999 palindromic in base 111, because its representation is 54 : 5 (base 111), and the concatenation of the digits (545) is palindromic.

Here is considering all numbers $\le 3*10^4$:

The number n vs the number of base representations of n for which it is a palindrome.

Here is considering all numbers $\le 10^5$:

enter image description here

1

There are 1 best solutions below

0
On

I don't have an answer as to why, but I've explored the function (using the Python code below), and identified the principal branches. The first division is into even bases (the top trunk) and odd bases (the bottom trunk). The second division is into bases that are divisible by $5$ (the top branch on each trunk) and bases that are not.

There are further refinements that can be seen on closer inspection, as well. For instance, the figure below shows just those bases that are multiples of $10$, with the dominant $\sqrt{b}$-ish behavior subtracted off. There is clearly a consistent difference between bases that are divisible by $20$ and those that are only divisible by $10$.

enter image description here

def decDigits(n, b):
  if n==0: return []
  return decDigits((n - (n%b))/b, b) + list(str(n%b))

def isPalindrome(n, b):
  fr = decDigits(n, b)
  rv = list(fr)
  rv.reverse()
  return fr == rv

def numBases(n):
  return len(filter(lambda(b):isPalindrome(n, b), xrange(2, n)))