1
$\begingroup$

I am trying to write a JAVA program that searches through pi to find a given string. However, I don't quite understand how you convert 3.141592...to D.DRSQLOLYR... (as seen on this site: here)? Could someone please carefully explain to me a simple algorithm for converting an irrational number such as pi into letters? Thanks!

  • 0
    Probably both...Does the arbitrary precision alter the output? e.g. if I calculate at x=101 instead of x=100 will I get different beginning values?2012-03-15

1 Answers 1

6

So $3 = D$, and that's that for the integer part.

Suppose I took the approximation .14159 for the fractional part, and I wanted to convert that to base 26. $.14159 \cdot 26 = 3.68134$. The integer part is $3$, so mark down another $D$.

Now $.68134 \cdot 26 = 17.71484$. The integer part is $17$, so we mark down $R$ and continue.

$.71484 \cdot 26 = 18.58584$. The integer part is $18$, so we mark down $S$.

So the beginning is $D.DRS$ - I didn't start with many decimals, so I will quickly lose precision now. To get better base 26 representations, you choose better decimal and or fractional representations.

You might ask, why does this work?

The idea is that we are looking at $.14159 = c_1 26^{-1} + c_2 26^{-2} + c_3 26^{-3} + ...$ And this looks awkward. But if we multiply by $26$, we get

$26 \cdot .14159 = c_1 + c_2 26^{-1} + \ldots$. So the integer part is the first coefficient, which is the first decimal digit. Then repeating gives the next ones. And this is very easy to automate, as it's essentially presented in algorithmic form.

  • 0
    OH, ok. I think I understand now? Thanks! :)2012-03-15