# Brain Teaser for Pi Day

Alex has come up with a great idea for Pi Day. We should celebrate by trying to come up with a way, in SQL, of generating a an accurate value for Pi. If only Archimedes had possessed a laptop, his work would have been easier!

To celebrate Pi Day (14th March) we have decided to introduce a competition: Using T-SQL, find the best approximation of Pi number as a ratio of two integer numbers, both less than 1000. The ideal solution is a ratio that cannot be reduced.

Pi Day is the brainchild of the physicist Larry Shaw of San Francisco’s Exploratorium, and is observed on March 14 (3/14 in American date format), due to ? being roughly equal to 3.14: At 1:59:26 pm (3.1415926) pizza and fruit pies are consumed; Celebrations can be extended: on March 14, 2004, Daniel Tammet calculated and recited 22514 decimal digits of pi.

We owe it to Archimedes that he proved that the area of a circle is equal to that of a triangle of base equal to the circumference of the circle and its height equal to the radius. The problem then became one of determining the ratio between circumference and diameter. Archimedes had to determine the value of Pi by means of seeking the limit approached by the sides of regular polygons both inscribed within, and circumscribed outside the circle. We don’t know how long it took him without a laptop!

Currently we developers do not need to do it ourselves – many languages provide Pi number for us. For instance, SQL has PI() and you can use System.Math.PI in C#. However, calculating Pi as an exercise or as a brainteaser is still a fascinating way of understanding the scale of the achievements of the Ancient Greek mathematicians..

Consider the following brainteaser: using only commands, features and functions described in Books Online except for PI(), find the best approximation of Pi number as a ratio of two integer numbers, both less than 1000. The ideal solution is a ratio that cannot be reduced. You can use a helper table populated with integer numbers.

We’ll reveal a solution a week after Pi Day (2009.3.14) The author of the winning solution, nominated by our distinguished panel of judges on accuracy, clarity, and ingenuity, will receive a \$50 Amazon token.