I put together this example to illustrate some general R programming principles for my Data Science class at iXperience. The idea is to use Buffon’s Needle to generate a stochastic estimate for pi.

Here are the results (click on the image for an interactive version). The orange line is the reference value and the blue line represents the results of the computation.