Oh, you can try. For example, 22/7 is a pretty good approximation. But it’s not pi. (We could have celebrated Pi Day on July 22, since most of the world uses the day-month-year format for dates, and that would be 22-7.)
But maybe you’re not inclined to take my word for it. So here’s what I’m going to do: I’m going to use a brute-force algorithm I made in Python to generate all possible integer fractions and see if one of them equals pi.
No Pi in Python
What’s a brute-force method? It’s a way of solving a problem that doesn’t require cleverness, just a ton of work. My program starts with the fraction 1/1 and methodically ratchets it up by adding 1 to the numerator or the denominator. Here’s the recipe:
– Take the fraction (u/v) and compare to pi
– If u/v is less than pi, add one to the numerator (u+1)
– If u/v is greater than pi, add one to the denominator (v+1)
– If u/v is equal to pi, you win. You just proved that pi is rational.
So the series starts like this: 1/1, 2/1, 3/1, 4/1, 4/2, 5/2, 6/2, 7/2, 7/3, 8/3 … I mean, you could do this on paper, but you’d soon go mad. I ran my program to iterate 1,000 times. (If you want to see the code, here it is on Google Colab.) Then I plotted the decimal value for all 1,000 fractions (Since the horizontal axis goes from 1 to 1,000, I’m using a log scale to compress it.)
After 1,000 runs, I have a fraction of 760/242. This is a fine value for pi. It’s accurate to two decimal places—the standard 3.14, which is what a lot of people use anyway. But it’s not pi. Oh, well, how about 500,000 iterations?
Services Marketplace – Listings, Bookings & Reviews