Lesson goal: Finding patterns in Pi

Previous: Palindromic squares | Home | Next: Patterns in Pi ($\pi$) (more)

There is no shortage of lore and stories about patterns or messages in the number $\pi$ (=3.1415...). To allow you to practice with strings, this lesson will let you do a little "data mining" yourself in the first 10,000 digits of $\pi$. What can you find with your programming skills?

Special for this lesson, we've predfined a string, called bigpi, that contains the first 10,000 digits of $\pi$. You can see the digits by running the single line print(bigpi). Also try print(string.len(bigpi) if you doubt the digits are there. Using the string.sub function, we can pick digits of $\pi$ out of this big string and examine them.

Here is something to think about. We've given you the first 10,000 digits of $\pi$ in the string bigpi. It is made of the digits from 0 to 9 (10 digits). If the digits in $\pi$ are uniformly used, how many times would you expect each digit to appear in the first 10,000 digits? The lesson below will allow you to measure this.

If you find anything interesting, let us know!

Now you try. Fix the for-loop and if-statement to loop through all 10,000 digits, and extract the single digit at position i in the string bigpi.

Type your code here:

See your results here: