15-100 Sections U-V-AA / Spring 2009 / Quiz 5
30 Minutes

3 Questions – 10 minutes per question


Notes:

1.      Palindromic Pi Digits
Here are the first few lines from the file millionDigitsOfPi.txt (now on your desktop):
1415926535 8979323846 2643383279 5028841971 6939937510
5820974944 5923078164 0628620899 8628034825 3421170679
8214808651 3282306647 0938446095 5058223172 5359408128

As you can see, the file consists of 10-digit blocks (100,000 of them).  As it turns out, two of these blocks are palindromes (same forwards as backwards).  The first one is 0136776310.  Write a method, printPiPalindrome, that locates and prints the second (and only the second!) palindromic block.

2.      Smallest Pi Block
We can view each 10-digit block in the file millionDigitsOfPi.txt as a number between 0 and 10 billion.  Write a method, printSmallestBlock, that locates and prints the smallest 10-digit block in this file.  You will have to think about overflow, and you may assume that the smallest block is less than one billion in any case (this simplifies the problem!).

3.      Odds of Zero-Free Blocks
Of the first 15 blocks listed above, 3 of them (curiously, the first 3) do not contain any zeroes.  That’s 3/15, or 20%.  To see if this is above or below the expected value, write a method, printZeroFreeOdds, that uses Monte Carlo methods to compute and print the odds that one block of 10 random digits does not contain any zeroes.  As usual, use enough trials to get a reasonably accurate result.  Hint:  remember to create only one instance of Random!

4.      Bonus/Optional:  Pi is Pseudo-Random?
Are the digits of pi a good source of pseudo-random numbers?  Write a method, testRandomness, that tests this theory against the first million digits of pi in the given file, and prints the result of the test (either “yes – fairly random” or “no – not so random”, perhaps with some numeric value(s) to back up the conclusion).  Write a brief comment in your Java file explaining how your test works.