Post Pi Day Coding Project: Let's Uncover the Hidden Words in Pi

Let's Uncover the Hidden Words in Pi

Today isn't actually Pi Day, but I was unable to get this article out in time. Pi Day was actually yesterday, March 14th (3.14), so let's call this a post-Pi Day treat!

I've usually stuck to computers and security in the past, so I thought I'd toss things up a bit and give you all a dose of computers and math! Let's look at some Java code that I've been writing for the past couple days. It may not be practically useful, but it is entertaining to do and is a great example of the power of programming. You can really use it for everything and anything, no matter how seemingly useless, so it's a great skill to develop!

What Does the Code Do?

What it's supposed to do is convert any irrational number (such as pi, tau, or log2) from numbers to letters, then allow you to search for words. I already took the liberty of converting the first 4,000,000 digits of pi for you, which took over an hour to do, if you were curious (Source-code, pi_data).

There is an option to use any number you would like, you just have to download it, format it and change the code to point to that file. I haven't had the time to make it into a super user-friendly app that you just double-click to use, but see my Java Process Killer App article for a how-to on setting up Java and running the source code, if you're unfamiliar with how to do that. Also, check out the picture below, which is how your files should look.

Post Pi Day Coding Project: Let's Uncover the Hidden Words in Pi

I didn't test it a ton, but it should be robust enough for entertainment and learning purposes. Now, I'll go over the major parts of how the code functions and discuss along the way how pi, chaos theory, and this computer program possibly relate.

How Was Pi Converted to Letters?

What I did was read in the first two numbers, then the next two, and so on, and each time I took the modulus 26 of each, so that we always have a number between 0 and 25. Each number is then mapped to a letter: "a" is mapped to 0, "b" to "1"... "z" to 25, so that we can easily convert between the two.

For example, the first two leading decimal digits of pi are 14 (pi = 3.141592...), thus we do 14mod26 = 14, and 14 corresponds with the letter "O". A more mathematically correct approach would be to convert to base-26, but for simplicity and my utter confusion of number theory, I decided to just do it this way.

At the heart of it all, how you convert is somewhat arbitrary, as the words you find are purely coincidental. Or are they? We will get to that.

What's the Probability of Finding Any Given Word?

In calculating this, I assumed that pi was random and that each letter has an equal chance of being chosen. If you look at the graph below (assuming my calculations were vaguely correct), you can see that as you increase the size of the word, the less likely it is to find it. Once we hit words of 6 or longer, our chances quickly deteriorate.

The formula used was [1-(1-(1/26)^N)^(g-N+1)], where N= word length and g=the number of letters you have.

Post Pi Day Coding Project: Let's Uncover the Hidden Words in Pi

When I looked up words, there were a good number of words of length N <= 4 that I was unable to find. This made me question my calculated probabilities. Or perhaps the way we converted to letters caused a divergence of sorts, which gave favor to a particular sequence of characters? (If you find a major mistake, please alert me).

Also, I had to beg the question: Is pi really random in the first place? I mean, if you randomly took 4 million letters, you would think just about every 4 letter word would have appeared. Right?

Is Pi Random?

The answer? No one has really proved it yet! Pi goes on forever, and thus far we haven't found a pattern, though a while ago some Canadian scientists/mathematicians came up with a way of calculating the nth digit of pi without having to first generate the preceding digits. This would imply pattern to me, but I am not sure? More on that here.

What do you think, is pi truly random? What words have you found or not found? Have you discovered some mystical pattern in pi? Comment below!

Please feel free edit and experiment with the code as you please. If you make any significant improvements, send the code to invisiblecomputer314@gmail.com and I will change the link to the updated file. 

If you have any questions, just ask somewhere in the forum, comments, or send me a message!

Follow us on:

Just updated your iPhone? You'll find new Apple Intelligence capabilities, sudoku puzzles, Camera Control enhancements, volume control limits, layered Voice Memo recordings, and other useful features. Find out what's new and changed on your iPhone with the iOS 18.2 update.

Photos by me, drzy.com

3 Comments

Apparently the links to download the files weren't working, but they should be now! :)

maybe pi changed them when you turned away lol interesting acticle thanks jt

Yes, it doesn't want us to know all it's dirty little secrets? haha

Share Your Thoughts

  • Hot
  • Latest