Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Pi Into Letters?

Tags:

java

numbers

For Pi Day, I am trying to write a Java program that tries to find a given word in Pi (or another given irrational number). I almost have it all completed, but I am conflicted about how I should convert each digit/digits of pi into a letter. I thought of saying: A=01, B=02, C=03...Y=25, Z=26.

However, I then felt bad for all the poor number sequences that don't even have a chance since any sequence that does not begin with a "0" or "2" will be disregarded entirely. This means 80% of sequences are irrelevant?

Can I do a base-26 to base-10 conversion? Not sure how to do that code-wise if that is indeed a proper solution?

Thanks!

like image 254
Mr_CryptoPrime Avatar asked Feb 22 '23 04:02

Mr_CryptoPrime


1 Answers

You can convert Pi from its base-10 form to any other base (i.e. base 26, where you only use letters A-Z, and not numbers 0-9), using a method like this one. The resulting "digits" will be all letters.

You'll have to modify the fromDecimalToOtherBase method so that it only outputs letters. Otherwise, it should be pretty straight forward, and it's the same algorithm to convert between decimal and any arbitrary base.

Just for kicks, I also found this page which contains an arbitrary base converter. If you enter Pi without the decimal, and enter "26" for the destination base, it'll do the conversion (though it still uses digits 0-9, so it doesn't "solve" the problem, the way you want to).

like image 85
jefflunt Avatar answered Mar 08 '23 12:03

jefflunt