Find least binary palindrome greater than a natural number
I am looking for an efficient way to generate the least binary number, b, that yields a natural number greater than a given natural number, d.
A small example would be d = 15, binary = 1111, and for which the least largest b = 10001 (decimal value 17).
Assume the natural number of interest, d, is 1 quadrillion (10^15) for which the binary representation, b, is:
‘11100011010111111010100100110001101000000000000000’
I have tried one standard approach from the literature, which is to form the sum b + reverse(b) and check to see if the
result is a palindrome that yields a natural number that is just above d. So far, after many cycles, that hasn’t produced anything.
There is no guarantee this method will always work, for example, it fails for the number 196.
There is a wealth of tantalizing clues in the "OEIS," the Online Encyclopedia of Integer Sequences"
(for example: https://oeis.org/A006995) but nothing is given there in terms of MATLAB code.I am looking for an efficient way to generate the least binary number, b, that yields a natural number greater than a given natural number, d.
A small example would be d = 15, binary = 1111, and for which the least largest b = 10001 (decimal value 17).
Assume the natural number of interest, d, is 1 quadrillion (10^15) for which the binary representation, b, is:
‘11100011010111111010100100110001101000000000000000’
I have tried one standard approach from the literature, which is to form the sum b + reverse(b) and check to see if the
result is a palindrome that yields a natural number that is just above d. So far, after many cycles, that hasn’t produced anything.
There is no guarantee this method will always work, for example, it fails for the number 196.
There is a wealth of tantalizing clues in the "OEIS," the Online Encyclopedia of Integer Sequences"
(for example: https://oeis.org/A006995) but nothing is given there in terms of MATLAB code. I am looking for an efficient way to generate the least binary number, b, that yields a natural number greater than a given natural number, d.
A small example would be d = 15, binary = 1111, and for which the least largest b = 10001 (decimal value 17).
Assume the natural number of interest, d, is 1 quadrillion (10^15) for which the binary representation, b, is:
‘11100011010111111010100100110001101000000000000000’
I have tried one standard approach from the literature, which is to form the sum b + reverse(b) and check to see if the
result is a palindrome that yields a natural number that is just above d. So far, after many cycles, that hasn’t produced anything.
There is no guarantee this method will always work, for example, it fails for the number 196.
There is a wealth of tantalizing clues in the "OEIS," the Online Encyclopedia of Integer Sequences"
(for example: https://oeis.org/A006995) but nothing is given there in terms of MATLAB code. binary palindromes, number theory MATLAB Answers — New Questions