Mr_CryptoPrime
Mr_CryptoPrime

Reputation: 638

Converting Pi Into Letters?

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!

Upvotes: 4

Views: 3940

Answers (2)

jefflunt
jefflunt

Reputation: 33954

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).

Upvotes: 4

Guffa
Guffa

Reputation: 700372

You can make the alphabet wrap around and use all codes.

00 = A
01 = B
...
24 = Y
25 = Z
26 = A
27 = B
...

Or, why bother with base 10 at all? Just express the number in base 26 to start with, and each digit represents a letter.

pi = D,DRSQLOLYRTRCLRGGUKBJKPSRFVKRODHLJRFSZSOXNHXZ...

Upvotes: 3

Related Questions