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:
This code will not run! What ending limits to you need on the for loop to examine all 10,000 digits
in string bigpi? Next, what will you put to the left of the == sign in the if statement
to extract the single digit of $\pi$ at position i?
If you figure this out, how could you search for multiple digits of other "mythological numbers,"
like todays date, 13 (unlucky number), 5150, 23, or 666? What is your favorite or "lucky" number.
Can you find it in $\pi$?
Show a friend, family member, or teacher what you've done!
Here is a share link to your code:
Does your code work? Want to run it on your iPhone?
Here's your code:
Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.
Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into
Then click the "Use on iPhone" button that you'll see.