## Two-Base Palindromes

### October 21, 2014

I wanted to do this exercise as a follow-up to the earlier exercise on generating palindromes, but didn’t get around to it until now.

Your task is to write a program that generates a list of numbers that are palindromes in base 10 and base 8; for instance 1496941_{10} = 5553555_{8}. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

A quick solution to perl (probably pipe the output through sort -n to get them fully in correct order)

In Java, pretty cheesy when using StringBuilder.

Here’s the list of dual-base palindromes I got when I let my program run overnight:

Java8 based on previous palindrom solution

Haskell: http://codepad.org/mTNnPb8l

Here is a better one in Java. Its uses two generators and works like “merging” them.

Generate the octal palindromes directly in binary and for each one check if we have one in base 10 as well.

About 10 mins to go up to 21 octal digits (we then run out of bits). The highest seems to be 322742453555354247223 so actually the second half of that time doesn’t find anything.

Here’s a Python version, so we aren’t limited to what will fit in a uint64_t.

Going a couple of hours now and up to 2650626939396260562 / 223107262414262701322.

After running for 4 days, my Python program has got well beyond 64 bit values and extended the list above with:

9843207767677023489 1042320625005260232401

32300361188116300323 3401017365665637101043

44643103022030134644 4656141232552321416564

77580854944945808577 10322464410401446422301

202693712161217396202 25763605624542650636752

371911868919868119173 50245203044744030254205

375183597404795381573 50532677140404177623505

375586160515061685573 50561160560606506116505

379080765242567080973 51063153270407235136015

473317002010200713374 63242276231313267224236

494635531909135536494 65501623271217232610556

552868393727393868255 73742270655755607224737

556362998454899263655 74244263365556336244247

579927810111018729975 76700353553235535300767

2503498805115088943052 417334063462264360433714