I need to generate all palindromic numbers for a given number base (which should be able to be of size up to 10,000), in a given range. I need a efficient way to do it.

I stumbled upon [this answer](https://stackoverflow.com/a/6401324/5821790), which is related to base 10 directly. I'm trying to adapt it to work for "all" bases:

```
public static Set<String> allPalindromic(long limit, int base, char[] list) {

    Set<String> result = new HashSet<String>();

    for (long i = 0; i <= base-1 && i <= limit; i++) {
        result.add(convert(i, base, list));
    } 

    boolean cont = true;
    for (long i = 1; cont; i++) {
        StringBuffer rev = new StringBuffer("" + convert(i, base, list)).reverse();
        cont = false;
        for (char d : list) {   
                String n = "" + convert(i, base, list) + d + rev;
                if (convertBack(n, base, list) <= limit) {
                    cont = true;
                    result.add(n);
                }
        }
    }

    return result;
}

```

`convert()` method converts a number to a string representation of that number in a given base using a list of chars for digits.

`convertBack()` converts back the string representation of a number to base 10.

When testing my method for base 10, it leaves out two-digit palindromes and then the next ones it leaves out are 1001,1111,1221... and so on.

I'm not sure why.

Here are the [conversion methods](https://pastebin.com/TjQxNtYi) if needed. 

---

**Turns out, this gets slower with my other code because of constant conversions since I need the all numbers in order and in decimal. I'll just stick to iterating over every integer and converting it to every base and then checking if its a palindrome.**